如何在硒定位器中使用正则表达式 [英] How to use regex in selenium locators
本文介绍了如何在硒定位器中使用正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 selenium RC,例如,我想获取具有匹配属性 href 的所有链接元素:
I'm using selenium RC and I would like, for example, to get all the links elements with attribute href that match:
http://[^/]*\d+com
我想使用:
sel.get_attribute( '//a[regx:match(@href, "http://[^/]*\d+.com")]/@name' )
它将返回与正则表达式匹配的所有链接的 name 属性列表.(或类似的东西)
which would return a list of the name attribute of all the links that match the regex. (or something like it)
谢谢
推荐答案
一个可能的解决方案是使用 sel.get_eval()
并编写一个返回链接列表的 JS 脚本.类似于以下答案:硒:是否有可能在硒定位器中使用正则表达式
A possible solution is to use sel.get_eval()
and write a JS script that returns a list of the links. something like the following answer:
selenium: Is it possible to use the regexp in selenium locators
这篇关于如何在硒定位器中使用正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文