gpt4 book ai didi

python - 如何访问selenium中具有相同类名的第二个元素

转载 作者:行者123 更新时间:2023-11-28 21:54:41 24 4
gpt4 key购买 nike

我的网页上有两个具有相同类名的元素,我正在尝试访问第二个元素,但我无法做到这一点。我尝试 [position=1] 并将 [1] 放在我的 xpath 表达式的末尾

driver.find_element_by_xpath("//div[@class='tableType value']")

以上返回以下2个元素

我试过了

driver.find_element_by_xpath("//div[@class='tableType value']")[1]
driver.find_element_by_xpath("//div[@class='tableType value'][position=1]")

有人可以帮我解决这个问题吗?

谢谢

最佳答案

使用

driver.find_element_by_xpath("(//div[@class='tableType value'])[2]")

driver.find_element_by_xpath("(//div[@class='tableType value'])[position()=2]")

XPath 从 1 开始计数,所以第二个元素在 position() 2

关于python - 如何访问selenium中具有相同类名的第二个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23819397/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com