0
votes

I'm running a selenium-webdriver javascript scraper, which logs into a site and clicks a button that launches a new tab/window. I'm trying to switch the driver to focus on the newly generated window, but Selenium cannot find it. The code I have to look:

driver.sleep(10000).then(function() {
    driver.getAllWindowHandles().then(function(d) {
        console.log(d);
    })
})

Which prints

[ '287ab61a-b155-46de-a2a6-298e0e98e440' ]

Which is the original browser window. What could cause Selenium to not pick up on the new window?

1
try to print the size of number of elements you are getting from the method getAllWindowHandles() - Paras
I just tried. The output: 1 - thisisnotabus
are u sure new windows are getting opened? - Paras
I can see it, as I'm not running headless. - thisisnotabus

1 Answers

0
votes

This is what I use whenever I need to switch to a new tab:

const tabs = await driver.getAllWindowHandles();
await driver.switchToWindow(tabs[1]);

If you want to switch back to the main tab just use tab[0].