Puppeteer: How to handle multiple tabs?

后端 未结 8 795
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 09:09

Scenario: Web form for developer app registration with two part workflow.

Page 1: Fill out developer app details and click on button to create Application ID, which

8条回答
  •  醉梦人生
    2020-12-13 09:52

    This will work for you in the latest alpha branch:

    const newPagePromise = new Promise(x => browser.once('targetcreated', target => x(target.page())));
    await page.click('my-link');
    // handle Page 2: you can access new page DOM through newPage object
    const newPage = await newPagePromise;
    await newPage.waitForSelector('#appid');
    const appidHandle = await page.$('#appid');
    const appID = await page.evaluate(element=> element.innerHTML, appidHandle );
    newPage.close()
    [...]
    //back to page 1 interactions
    

    Be sure to use the last puppeteer version (from Github master branch) by setting package.json dependency to

    "dependencies": {
        "puppeteer": "git://github.com/GoogleChrome/puppeteer"
    },
    

    Source: JoelEinbinder @ https://github.com/GoogleChrome/puppeteer/issues/386#issuecomment-343059315

提交回复
热议问题