我想单击ID为{{1}的页面中显示的app-meter-tile
之一(页面中有很多app-meter-tile
列表中的数据) }或customer-info
id或offtake
。我尝试了下面的代码,但引发以下错误。我想知道我们如何才能基于customer name
单击或访问基于$eval
的选项,请告知。
xpath
超时或其他错误:TypeError:div.click不是函数 在C:\ work \ UiTests \ offline-login-check.js:59:15 在process._tickCallback(internal / process / next_tick.js:68:7)
答案 0 :(得分:1)
为什么您的代码不起作用
此方法访问具有提供的选择器的第一个元素,并返回其 id :
var div = await page.$eval(".mb-10[id='customer-info']",
element=> element.getAttribute("id"))
ID是一个字符串,并且没有click
函数。
正确使用page.$eval
的方法:
await page.$eval(".mb-10[id='customer-info']", element => element.click())
另一种方法 是通过获取元素的句柄然后单击它:
const div = await page.$(".mb-10[id='customer-info']");
await div.click();