这是一个黄瓜木偶项目。 在下面的代码中,我在最后一行出现错误,提示“无法读取未定义的属性'0'”
我想做的是首先找到一个具有textContent为“ Revenue”的链接 这似乎可行
我创建一个 a 元素textContents的结果数组。 然后,我找到具有textContent of Revenue的元素的索引。 这就是 foundIndex 。 0是正确的索引
然后我要点击该特定 a 元素 因此,我尝试创建一个数组 result2 ,它是没有文本内容的 a 元素,并使用 foundIndex 来标识目标元素。
点击时,我收到错误消息
async function clickRevenueFolder() {
const result = await this.page.evaluate(() => {
[...element] = document.querySelectorAll('a[href^="#function"');
return [...element.map(x => x.textContent.trim())];
});
const folderTitle = 'Revenue';
const foundIndex = result.indexOf(folderTitle)
console.log('found index : ' + foundIndex);
//Found correct Index!!!!!!
//now need to click on associated a
const result2 = await this.page.evaluate(() => {
return [...element] = document.querySelectorAll('a[href^="#function"');
});
const selector = result2[foundIndex];
await this.clickSelector(selector);
}
在下面尝试了此方法-也没用
const result2 = await this.page.evaluate(() => {
const nodeList= document.querySelectorAll('a[href^="#function"');
return [...nodeList]
});
const selector = result2[foundIndex];
await this.clickSelector(selector);