【发布时间】:2021-01-28 09:57:47
【问题描述】:
当我尝试使用下面的选择器切换到 TestCafe 中的 iframe 时:
const iframeCase = Selector('iframe').withAttribute('title', 'SR-1234');
我成功切换到 iframe。但是由于标题中的数字每次测试运行都会改变。我需要添加一个正则表达式,就像我在这里做的那样:
const iframeCase = Selector('iframe').withAttribute('title', /SR\-[0-9]{0,6}/);
但是使用这个正则表达式变体,我收到以下错误: 与指定选择器匹配的元素不可见。
这是我要选择的 iframe:
<iframe name="PegaGadget7Ifr" id="PegaGadget7Ifr" border="0" frameborder="0"style="" title="SR-1234"
data-hammerhead-focused="true"></iframe>
有谁知道我做错了什么?我首先认为我的正则表达式是错误的。但其他组合如:
/SR/
/SR\-[0-9][0-9][0-9][0-9][0-9]/
/SR[-0-9][0-9][0-9][0-9][0-9]/
也都失败了。不幸的是,我无法共享正在测试的应用程序,因为它在封闭的公司环境中运行。
testcafe: 1.10.1
Chrome 87.0.4280.141 / Windows 10.
node: v14.15.4
【问题讨论】:
标签: regex testing automated-tests e2e-testing testcafe