power_settings_new
How to click on the last child of a div after each page load?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
0 votes

First you have to get all divs by using driver.findElements function.

This will get you list of all webelements in form of List<WebElement>.

List<WebElement> allElements = driver.findElements(By.xpath("your/xpath/here"));

Now you can get the last WebElement  by using get function and passing your list size - 1.

WebElement lastElement = allElements.get(allElements.size()-1);

Hope that helps.

add
...