是否可以使用Tcl Selenium Webdriver接口在定位器中使用正则表达式搜索元素?

时间:2016-06-21 12:41:59

标签: selenium selenium-webdriver tcl selenium-chromedriver

是否可以搜索元素在定位器中使用正则表达式。

以下作品

set login [$window element by_class_name "frost-button"]

但以下情况不起作用。

set login [$window element by_class_name "*button"]

1 个答案:

答案 0 :(得分:1)

不,你不能。当您调用类似“by_class_name”的内容时,程序将尝试查找与您作为参数传递的类名完全匹配的元素。

因此,如果您尝试搜索包含字符串的类,则需要使用xpath或cssselector,但不使用正则表达式。

在Cssselector中,选择器是这样的:

*[class*='button']

另外,在Xpath中是这样的:

//*[contains(@class, 'button')]

我认为要将其转换为tcl字符串,您需要在字符串中插入一些斜杠。由于我不知道tcl,我最好不要尝试。