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

Is it possible to search elements using regular expressions in locators using Tcl Selenium Webdriver interface?

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

以下作品

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

但是下面的不行。

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

不,你不能。当您调用 "by_class_name" 之类的东西时,程序将尝试查找与您作为参数传递的 class 名称完全匹配的元素。

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

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

*[class*='button']

还有,在Xpath中是这样的:

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

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