繁体   English   中英

未找到 Puppeteer 选择器

[英]Puppeteer selector not being found

我在调试为什么未单击查询选择器时遇到问题 - 我可以在 chrome 中搜索它,而且如果在开发工具中使用 document.querySelector() 它会找到查询,这让我相信它是正确的,然而它并没有按下它,只是超时了

点击方法:

async function click(page, selector, timeout) {
await beforeAction(page, timeout);
await page.waitForSelector(selector);
await page.waitFor(200);
await page.click(selector);
}

执行的主要方法:

async function existingStart(page) {
await loadCookies(page);
await page.goto(
    "https://mc.s7.exacttarget.com/cloud/#app/Email/C12/Default.aspx?entityType=none&entityID=0&ks=ks%23Content"
    , {
        waitUntil: 'load',
        timeout: 0
    }
);
await page.waitFor(200);
const contentBuilderFrame = await findFrame(page, "contentbuilder");
const searchField = await contentBuilderFrame.$(".contentsearch > input");
searchField.focus();
await page.keyboard.type("20200903");
await page.waitFor(500);
await page.keyboard.press('Enter');
await page.waitFor(5000);
// Screenshot to check page state
await page.screenshot({

    path: "./screenshot.png",

    fullPage: true

});
await page.waitFor(500);
// Times out
await click(page, '#contentRepeater > div.repeater-viewport > div.repeater-canvas.scrolling > div > div > table > tbody > tr:nth-child(1) > td:nth-child(3) > div > div > div > div')

}

如果我在单击选择器之前调用 find Iframe 方法:

await findFrame(page, "contentbuilder");

什么都没有发生,它因 JSHandler 问题而出错,有没有人发生过类似的事情? 难道问题出在 Iframe 上? 奇怪的是 searchField 输入和按键都正常。 此外,它是相同的 iframe,所以我不应该调用 findFrame 两次。

行动前:

async function beforeAction(page, timeout) {
if (timeout != null) {
await page.waitFor(timeout);
}

var isLoading = await isPageLoading(page);

while (isLoading) {
await new Promise((resolve) => setTimeout(resolve, 1000));
isLoading = await isPageLoading(page);
 }
}

由于我们在评论中得出了答案,所以我将其张贴在这里以供遇到此问题的其他人使用。

由于目标选择器位于 iframe ( contentbuilder ) 中,因此要作为参数传递给 function click的上下文不是page ,而是 iframe 元素: contentBuilderFrame

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM