Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press Enter in popup using selenium

I m using Selenium to test my web application.

Here I want to click the enter button to select the values in list box. I have tried maximum all methods using javascript, sendkeys and Robot also. Everything is working fine in normal window, but when the popup appeared that time not working for this.

Has anyone faced this issue?

Kindly help me.

Thanks for advance.

like image 578
Akalyvan Avatar asked Aug 30 '25 18:08

Akalyvan


1 Answers

You need to switch the pop-up first and then you can perfrom action

Alert alertOK = driver.switchTo().alert();
alertOK.accept();

If the pop-up is not confirmation box then you need to switch and perform click operation

driver.switchTo().alert();
element.click();

OR If it is application pop-up then you can try below code

To switch to a popup window, you need to use getWindowHandles() and iterate through them.

In your code you are using getWindowHandle() which will give you the parent window itself.

String parentWindowHandler = driver.getWindowHandle(); // Store your parent window
String subWindowHandler = null;

Set<String> handles = driver.getWindowHandles(); // get all window handles
Iterator<String> iterator = handles.iterator();
while (iterator.hasNext()){
    subWindowHandler = iterator.next();
}
driver.switchTo().window(subWindowHandler); // switch to popup window

// Now you are in the popup window, perform necessary actions here

driver.switchTo().window(parentWindowHandler);  // switch back to parent window

Hope it will help you :)

like image 110
Shubham Jain Avatar answered Sep 02 '25 07:09

Shubham Jain