单击基于$ eval的div引发div单击不是puppeteer中的函数

时间:2019-09-13 23:55:46

标签: node.js puppeteer

我想单击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)

enter image description here

1 个答案:

答案 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();