尝试使用 $x 单击元素但会引发错误。尝试了不同的方法但没有运气,谁能让我知道下面的代码或任何其他使用xpath点击的方式有什么错误。
Error: Protocol error (Runtime.callFunctionOn): Target closed.
下面是代码
//通用函数.ts
module.exports = {};
module.exports.ToggleButton = async function ToggleButton(Question, QuestionLabelXpath) {
await page.waitForXPath(QuestionLabelXpath + "/descendant::label[text()='" + Question + "']/parent::div/descendant::button[@title='Edit']");
const editIcon = await page.$x(QuestionLabelXpath + "/descendant::label[text()='" + Question + "']/parent::div/descendant::button[@title='Edit']");
await editIcon[0].click();};
//questions.ts
const CommFun = require('./commonfunction');
test('Verify "question"',async() => {
CommFun.ToggleButton("question","//div[@role=\'tabpanel\']/div/div/div/div/div")
},30000);
在测试中尝试了 $$eval ,单击是有效的,但是当我将它放入函数中时它不起作用,它是否必须对函数调用做任何事情?
const CommFun = require('./commonfunction');
test('Verify "question"',async() => {
await page.$$eval('button[title=\'Edit\']', elements => elements[1].click());
},30000);