gpt4 book ai didi

Python:Selenium xpath 查找具有不区分大小写字符的元素?

转载 作者:行者123 更新时间:2023-11-30 23:30:57 25 4
gpt4 key购买 nike

我能做到

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

但我需要它忽略并匹配所有带有文本的元素,例如:“VieW LiSt”或“view LIST”

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

以上似乎不起作用。 lower-case() 位于 XPATH 1.0

最佳答案

仅 XPath 2.0 支持 lower-case() 函数。对于 XPath 1.0,您必须使用 translate()

示例代码在 stackoverflow answer 中给出.

编辑:selenium python 绑定(bind)网站有一个常见问题解答 - 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.

关于Python:Selenium xpath 查找具有不区分大小写字符的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20228962/

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