Is there a way to get element by XPath in Selenium WebDriver? (Python)

Is there a way to get element by XPath in Selenium WebDriver? (Python)

WebElements can be located with selenium WebDriver using XPaths. These are expressions that identify elements on a page based on certain details, such as, if the element contains a specific attribute or has a specific child node.

query = self.driver.find_element_by_xpath("//*[@class='central-textlogo-wrapper']")

To explain what the different parts of the xpath in the above statement do:


  • // means to select an element descending from the root element

  • * means the element can be of any type

  • @class means to select an element matching the class attribute of the WebElement.

See Working Example



Using Java

Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.