Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
140 views
by The go-to Tester (391 points)
How to click on the last child of a div after each page load?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

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.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...