1

I am using puppeteer to do tests with the browser, i've managed to do is to access a page, then i do click in a DOM element, after do click, the browser show me other view, in this view i do click in a button that open a pop up for do log in with facebook.

My question is:

how i can handler the other window for do login with facebook? this is code.

Example code:

import * as puppeteer from 'puppeteer';

const f = async () => {
console.log('..');

const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
page.setViewport({ width: 1200, height: 800 })
await page.goto('https://goalgoodies.herokuapp.com').catch(err => { console.log('error ', err); });

await page.screenshot({ path: 'screenshot.png' });

const resp = await page.click('a').catch(err => { console.log('error click', err); });

const inputElement = await page.$('.signin a').catch(err => { console.log('error selector', err); });

await inputElement.click().catch(err => { console.log('error click', err); });
await page.screenshot({ path: 'screenshot2.png' });

const fbBtn = await page.$('button[name=facebook]');
await fbBtn.click();
// here it's open pop up for do login with facebook
await page.screenshot({ path: 'clickpopup.png' });
};
f();

Apparently there is no way with puppeter to interact with other windows

Here another related question

In this post forum the user aslushnikov mentions something related with Target domain, but I can not understand what he means, or how to execute.

Any help would be appreciated.

Thank you

Frank
  • 11
  • 1
  • 3

2 Answers2

2

I think you are looking for Browser Contexts.

https://chromedevtools.github.io/devtools-protocol/tot/Target/#method-createBrowserContext

A sample implementation is discussed in details here,

https://github.com/cyrus-and/chrome-remote-interface/issues/118

Hope it helps.

Kannaiyan
  • 12,554
  • 3
  • 44
  • 83
1

To allow changing between open pages I created a simple utility method:

async function changePage(url) {
    let pages = await browser.pages();
    let foundPage;
    for(let i = 0; i < pages.length; i += 1) {
        if(pages[i].url() === url) {
            foundPage = pages[i];//return the new working page
            break;
        }
    }
    return foundPage;
}

This assumes your timing is correct for any newly opened windows, but that would be a different topic.

Bryce W
  • 123
  • 1
  • 7