Selecting WebElements with dynamically generated ids by xpath Selenium java

后端 未结 1 1018
有刺的猬
有刺的猬 2021-01-28 04:52

I need to select an element in a dropdown window. Every time I open the dropdown window in the site I am testing, the website randomly generates an id for that dropdown window.

相关标签:
1条回答
  • 2021-01-28 05:49

    Try this approach:

    Get all elements.

    java.util.List<WebElement> elements = driver.findElements(By.xpath("//div[@class='really long name for drop down menu']/ul/li[2]"));
    elements[elements.count - 1].click();
    

    That should click the last element with that particular class.

    0 讨论(0)
提交回复
热议问题