I 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 appreciate for any tips and supports Thanks
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With