Open
Description
Description
What we were trying to do?
- We are trying to write a selenium testcase for a website where we are clicking on a button to popup window. In the popup window we click on some element, this closes the popup window and we need to continue test on main window.
What we expected to happen?
- After the popup window closed, we should be able to continue test on main window
What actually happened?
- As soon as the popup window closes, the selenium session crashes with
ScriptTimeoutError
.
Test we are running:
Dummy-Test.zip
Error we are getting:
ScriptTimeoutError: Unable to execute request for an existing session: java.io.IOException: HTTP/1.1 header parser received no bytes
at Object.throwDecodedError (/Users/dummy-user/Work/dummy-test/node_modules/selenium-webdriver/lib/error.js:522:15)
at parseHttpResponse (/Users/dummy-user/Work/dummy-test/node_modules/selenium-webdriver/lib/http.js:589:13)
at Executor.execute (/Users/dummy-user/Work/dummy-test/node_modules/selenium-webdriver/lib/http.js:514:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async WebDriver.execute (/Users/dummy-user/Work/dummy-test/node_modules/selenium-webdriver/lib/webdriver.js:740:17)
at async click (/Users/dummy-user/Work/dummy-test/lib/browser/actions/clickElement.js:16:9)
at async World.<anonymous> (/Users/dummy-user/Work/dummy-test/features/stepDefinitions/decideware.js:53:5)
Reproducible Code
const { Builder, By, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
(async function handlePopupWindow() {
let driver = await new Builder().forBrowser('chrome').setChromeOptions(new chrome.Options()).build();
try {
// 1. Open main page
await driver.get('https://staging.decideware.com/test/sample/main.html');
// 2. Click on the button to open popup
const openPopupButton = await driver.findElement(By.xpath("//button[normalize-space()='Open pop up window']"));
await openPopupButton.click();
// 3. Wait and switch to popup window
const windows = await driver.getAllWindowHandles();
const mainWindow = windows[0];
await driver.wait(async () => {
const newWindows = await driver.getAllWindowHandles();
return newWindows.length > 1;
}, 5000);
const popupWindow = (await driver.getAllWindowHandles()).find(handle => handle !== mainWindow);
await driver.switchTo().window(popupWindow);
// 4. Wait for the record and click it
await driver.wait(until.elementLocated(By.id("Record 1")), 5000);
await driver.findElement(By.id("Record 1")).click();
// Optionally switch back to main window
await driver.switchTo().window(mainWindow);
console.log(`Record Selected: ${await driver.findElement(By.id("returnVal")).getAttribute('value')}`);
} catch (err) {
console.error('Error:', err);
} finally {
// Close all windows
await driver.quit();
}
})();