DEV Community

MOMO
MOMO

Posted on

Answer: selenium count elements of xpath

Use find_elements_by_xpath to get number of relevant elements

count = len(driver.find_elements_by_xpath(xpath))

Then click on the last element:

elem = driver.find_element_by_xpath(xpath[count])
elem.click()

Notice: the find_elements_by_xpath is plural in first code snippet

Top comments (0)