Getting Exception in Program of Handling Multiple Pop-up windows | Selenium Forum
P
Pushkar Bhadang Posted on 15/09/2020

Dear Team,

I am getting below Exception in Java program of Handling Multiple Pop-up windows. Please let me know what correction is required in this program so that web driver will interact with pop-up windows & close the pop-up windows.

Exception: Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Expected "handle" to be a string, got [object Undefined] undefined

Program:

public class MultipleWindows {

public static void main(String[] args) {

WebDriver driver = new FirefoxDriver();
driver.get("http://www.popuptest.com/popuptest12.html");

Set<String> winIds = driver.getWindowHandles();
System.out.println("Total Number of Window Popups: "+winIds.size());

Iterator<String> it = winIds.iterator();
String mainWindowId = it.next();
String popup1 = it.next();
String popup2 = it.next();
String popup3 = it.next();

System.out.println("Main Window id: "+mainWindowId);
System.out.println("Popup1 id: "+popup1);
System.out.println("Popup2 id: "+popup2);
System.out.println("Popup3 id: "+popup3);

driver.switchTo().window(popup1);
driver.close();
driver.switchTo().window(popup2);
driver.close();
driver.switchTo().window(popup3);
driver.close();
driver.switchTo().defaultContent();
driver.quit();
}
}

 

Output:

Total Number of Window Popups: 4
Main Window id: 18
Popup1 id: 4294967297
Popup2 id: 4294967298
Popup3 id: 4294967299
Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Expected "handle" to be a string, got [object Undefined] undefined


A
Ashish Thakur Replied on 17/09/2020

Please share the complete exception stack trace.


P
Pushkar Bhadang Replied on 17/09/2020

Please find below complete exception stack trace:

Exception in thread "main" org.openqa.selenium.InvalidArgumentException: Expected "handle" to be a string, got [object Undefined] undefined
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'DESKTOP-1CP8JFF', ip: '192.168.0.109', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_261'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 80.0.1, javascriptEnabled: true, moz:accessibilityChecks: false, moz:buildID: 20200831163820, moz:geckodriverVersion: 0.24.0, moz:headless: false, moz:processID: 13420, moz:profile: C:\Users\Pushkar Bhadang\Ap..., moz:shutdownTimeout: 60000, moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: a887d28a-8b12-4062-a57d-7c237303ad2e
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at org.openqa.selenium.remote.RemoteWebDriver$RemoteTargetLocator.window(RemoteWebDriver.java:903)
at windowpopups.MultipleWindows.main(MultipleWindows.java:28)


P
Pushkar Bhadang Replied on 21/09/2020

Dear Team,

Please let me know what correction is required in this program so that web driver will interact with pop-up windows & close the pop-up windows.


A
Ashish Thakur Replied on 22/09/2020

The error is possibly at MultipleWindows.java line number 28.


Related Posts