简体   繁体   English

未找到 Puppeteer 选择器

[英]Puppeteer selector not being found

I am having an issue debugging why a query selector is not being clicked - I can search for it in chrome and also if use the document.querySelector() in the dev tools it finds the query, which makes me believe that it is right, however it is not pressing it and just times out我在调试为什么未单击查询选择器时遇到问题 - 我可以在 chrome 中搜索它,而且如果在开发工具中使用 document.querySelector() 它会找到查询,这让我相信它是正确的,然而它并没有按下它,只是超时了

Click Method:点击方法:

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

Main Method That gets executed:执行的主要方法:

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')

} }

And if I call the find Iframe method before clicking on the selector:如果我在单击选择器之前调用 find Iframe 方法:

await findFrame(page, "contentbuilder");

Nothing really happens and it errors with a JSHandler issue, has anyone had anything similar happen?什么都没有发生,它因 JSHandler 问题而出错,有没有人发生过类似的事情? Could it be that the issue is Iframes?难道问题出在 Iframe 上? The odd thing is that the searchField input and keypress goes through just fine.奇怪的是 searchField 输入和按键都正常。 Moreover, it is the same iframe, so I shouldn't have to call findFrame two times.此外,它是相同的 iframe,所以我不应该调用 findFrame 两次。

beforeAction:行动前:

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);
 }
}

Since we came up with the answer in the comments, I'm posting it here for other people who come across this question.由于我们在评论中得出了答案,所以我将其张贴在这里以供遇到此问题的其他人使用。

As the targeted selector is in an iframe ( contentbuilder ), the context to be passed as argument the function click is not page but the iframe element: contentBuilderFrame .由于目标选择器位于 iframe ( contentbuilder ) 中,因此要作为参数传递给 function click的上下文不是page ,而是 iframe 元素: contentBuilderFrame

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

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