use*_*233 7 python selenium xpath
我的网页上有两个具有相同类名的元素,我正在尝试访问第二个元素,但我无法做到这一点。我尝试了 [position=1] 并将 [1] 放在我的 xpath 表达式的末尾
driver.find_element_by_xpath("//div[@class='tableType value']")
Run Code Online (Sandbox Code Playgroud)
以上返回以下2个元素
我试过
driver.find_element_by_xpath("//div[@class='tableType value']")[1]
driver.find_element_by_xpath("//div[@class='tableType value'][position=1]")
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?
谢谢
hel*_*cha 13
用
driver.find_element_by_xpath("(//div[@class='tableType value'])[2]")
Run Code Online (Sandbox Code Playgroud)
或者
driver.find_element_by_xpath("(//div[@class='tableType value'])[position()=2]")
Run Code Online (Sandbox Code Playgroud)
XPath 从 1 开始计数,所以第二个元素在position()2
| 归档时间: |
|
| 查看次数: |
18200 次 |
| 最近记录: |