Which browser automation tools can manage JavaScript popup windows?

I’m working with Python and Selenium WebDriver for browser automation. I’ve been testing different headless browser solutions but I’m running into issues with JavaScript popup handling.

I experimented with PhantomJS and Chrome in headless mode using various containerized setups. The problem I’m facing is that when my web application triggers popups using window.open(), the automation doesn’t seem to detect them properly. When I check driver.window_handles, it only shows one window handle instead of multiple ones.

Here’s a simple example of what I’m trying to accomplish:

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--headless')
browser = webdriver.Chrome(options=options)

browser.get('http://example-site.com')
popup_button = browser.find_element_by_id('open-popup')
popup_button.click()

# This should show 2 handles but only shows 1
print(len(browser.window_handles))

Is there a headless browser solution that properly supports JavaScript popup windows? I’m open to alternatives beyond containerized approaches if that would solve the popup detection issue.

chrome blocks popups by defualt, even with selenium. add --disable-popup-blocking to your chrome options. --disable-web-security might help too. fixed the same issue for me last month.

Try Playwright. I had the same popup issues with Selenium and Playwright fixed them completely. It handles window contexts way better for popups. Just use page.expect_popup() to wait for the popup, then grab it when it opens. Different API than Selenium but popup handling is miles better. It catches window.open() calls that Selenium totally misses, especially with complex JS apps. Headless mode works great with popups too, which was exactly what I needed. There’s a learning curve if you’re used to Selenium but the popup reliability made switching worth it.

Firefox handles popups way better than Chrome with Selenium. I switched after hitting the same window detection issues you’re dealing with. Firefox’s popup handling just works more consistently. Set your Firefox options to disable popup blocking and allow multiple windows. Firefox actually respects window.open() calls properly, especially with tricky JavaScript stuff. One heads up - add a short wait after clicking the popup trigger before checking window_handles. Sometimes the popup needs a second to register even though it opened fine.