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

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

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.

WebElement container = driver.findElement(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 and @class means to select an element matching the class attribute of the WebElement.

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.
4 + 4 =

Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.