简体   繁体   中英

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

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:

await findFrame(page, "contentbuilder");

Nothing really happens and it errors with a JSHandler issue, has anyone had anything similar happen? Could it be that the issue is Iframes? The odd thing is that the searchField input and keypress goes through just fine. Moreover, it is the same iframe, so I shouldn't have to call findFrame two times.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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