Python:seleniumxpath来查找不区分大小写字符的元素?

2024-10-01 07:45:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我能做到

search = "View List"
driver.find_elements_by_xpath("//*/text()[normalize-space(.)='%s']/parent::*" % search)

但我需要它忽略并匹配所有的元素,比如:“viewlist”或“viewlist”

^{pr2}$

以上这些似乎行不通。lower-case()在XPATH 1.0中


Tags: textview元素searchbydriverspaceelements
1条回答
网友
1楼 · 发布于 2024-10-01 07:45:07

只有XPath 2.0支持lower-case()函数。对于XPath1.0,必须使用translate()。在

示例代码在stackoverflow answer中给出。在

编辑: selenium python绑定站点有一个常见问题解答-Does Selenium 2 supports XPath 2.0 ?

Ref: http://seleniumhq.org/docs/03_webdriver.html#how-xpath-works-in-webdriver

Selenium delegate XPath queries down to the browser’s own XPath engine, so Selenium support XPath supports whatever the browser supports. In browsers which don’t have native XPath engines (IE 6,7,8), Selenium support XPath 1.0 only.

相关问题 更多 >