我在使用 testcafe 时遇到了一个非常奇怪的错误。在我的网站之一上,我无法选择 div 元素,但我仍然可以选择其他元素。所以
await t.click(Selector("span").withAttribute('id', 'foo'));
await t.click(Selector("p").withAttribute('id', 'foo'));
await t.click(Selector("button").withAttribute('id', 'foo'));
await t.click(Selector("input").withAttribute('id', 'foo'));
工作正常
await t.click(Selector("div").withAttribute('id', 'foo'));
会抛出以下错误:
Function that specifies a selector can only return a DOM node, an array of nodes, NodeList, HTMLCollection, null or undefined. Use ClientFunction to return other values.
这只发生在我的一个特定网站上。这可能是什么?我可以在脚本中做什么来禁止 testcafe 选择器获取“div”元素?现在真的没有想法。
最佳答案
如果您将返回值不正确的函数作为选择器参数传递,则可能会出现此问题:
test('Return non-DOM node', async () => {
await Selector(() => 'hey')();
});
但是,如果您使用字符串作为参数来指定选择器,则不应发生该错误。请检查您是否未将函数传递给 Selector 对象。
如果您的选择器定义正确,但问题仍然出现,请分享示例(HTML 页面或您网站的公共(public)网址)和完整的测试代码来演示该问题。
关于javascript - testcafe 选择器未找到 'div' 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65736289/