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

标签 python xpath selenium

我能做到

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/

相关文章:

javascript - 删除 Chrome 的 "translate"DOM 属性

python - 使用 Python Selenium 查找 span 标记的兄弟/父级

python - 重新调整绘图的一个轴的大小

python - Rasa NLU 模型不起作用。属性错误: 'str' object has no attribute 'load'

python - Z3 中的精确 n 编码

javascript - 从 JavaScript 数组中删除对象

python - 如何使用具有相同类名的scrapy抓取内容

java - 创建自定义 TestNG 报告 - WebDriver

python - 如何在 Selenium Python 绑定(bind)中等待并获取 Span 对象的值

Python数据框sume迭代