2024-06-26 00:25:19 发布
网友
我需要使用以下xpath在一些结构基本相同的网页中查找特定元素:
//*[@id="detailPCTtableHeader"]/tbody/tr[10]/td[2]/div/span/span[1]/text()
问题是在某些页面tr[10]是tr[11]。你知道吗
tr[10]
tr[11]
有没有办法告诉Selenium搜索tr[10]或tr[11]?你知道吗
您可以使用position()来评估索引:
position()
element = driver.find_element_by_xpath("id('detailPCTtableHeader')/tbody/tr[position()=10 or position()=11]/td[2]/div/span/span[1]")
"Is there a way to tell Selenium to search for tr[10] or tr[11]?"
使用position():
tr[position() = 10 or position() = 11]
或者,如果一次只存在tr[10]和tr[11]中的一个,这意味着它总是最后一个tr,您可以简单地使用last():
tr
last()
tr[last()]
您可以使用
position()
来评估索引:使用
position()
:或者,如果一次只存在
tr[10]
和tr[11]
中的一个,这意味着它总是最后一个tr
,您可以简单地使用last()
:相关问题 更多 >
编程相关推荐