Python:Selenium xpath 以查找不区分大小写字符的元素? [英] Python: Selenium xpath to find element with case insensitive characters?

查看:35
本文介绍了Python:Selenium xpath 以查找不区分大小写字符的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以做到这一点

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

但我需要它忽略并匹配所有带有文本的元素,例如:查看列表"或查看列表"

but I need it to ignore and match all elements with text like: "VieW LiSt" or "view LIST"

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

以上似乎不起作用.lower-case() 在 XPATH 1.0 中

The above doesn't seem to work. lower-case() is in XPATH 1.0

推荐答案

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

The lower-case() function is only supported from XPath 2.0. For XPath 1.0 you will have to use translate().

示例代码在此 stackoverflow 答案.

selenium python 绑定站点有一个常见问题解答 - Selenium 2 支持 XPath 2.0 吗?:

The selenium python bindings site has a FAQ - Does Selenium 2 supports XPath 2.0 ?:

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

Selenium 将 XPath 查询委托给浏览器自己的 XPath引擎,所以 Selenium 支持 XPath 支持任何浏览器支持.在没有原生 XPath 引擎的浏览器中(IE6,7,8), Selenium 仅支持 XPath 1.0.

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 以查找不区分大小写字符的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆