Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I click on a popup window in selenium Java

enter image description hereI am new to selenium and try to automate (using selenium Webdriver in Java for Window and using Chrome Driver) an App (ABC Project) which contains a Registration Form.

After completing the form and click on Registration Button I get a popup info message (modal) with close (X) & OK Button & Headline in the message: Under ABC Project the following is displayed & Text which informs the user that the registration was successful.

I have tried several ways to click on OK button in this popup window but no success:

1. 

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

 2. 

    driver.findElement(By.xpath("//input[@value = 'alert']")).click();
               Alert javascriptAlert = myTestDriver.switchTo().alert();
               System.out.println(javascriptAlert.getText()); // Get text on alert box
               javascriptAlert.accept();
               ----> in this case I get only the text of the opened tab (from registration window: driver.getTitle();:ABC Project) but not the text of teh Info message(to see in logger.info) 

 3. 

    String winHandleBefore =   
        driver.getWindowHandle();
               driver.findElement(By.xpath("//div[@class='col-md-4']/button[1]")).click();
        // Xpath of register Button
               Set handles = driver.getWindowHandles();    ..... --->>, In this case, I don't get any Window Handler of new window the window handler from old and new are the same

Additional Hint:

  • I am also not able to click anywhere else in Window to skip the popup window
  • In Google Developer tool I don't see also any source code and no Elements from the popup window (when the popups appear.
  • I heard from developer that this window is a javascript but I don't see anything in source code too (it did not also work with solution b above)

I appreciate for any tips and supports Thanks

like image 378
AKADO Avatar asked Dec 18 '25 06:12

AKADO


1 Answers

This picture posted looks like a javascript alert.

So the below code should have worked.

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

Maybe it is a wait issue. Try WebDriverWait

Alert alert = new WebDriverWait(driver, 20).until(ExpectedConditions.alertIsPresent());
alert.accept();
like image 56
Sighil Avatar answered Dec 21 '25 17:12

Sighil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!