Alert handling in Selenium WebDriver (selenium 2) with Java
This is what worked for me using Explicit Wait from here WebDriver: Advanced Usage
public void checkAlert() {
try {
WebDriverWait wait = new WebDriverWait(driver, 2);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
} catch (Exception e) {
//exception handling
}
}
How to handle pop-up or alert in selenium?
First that's not popup that's an Iframe.
you can get more information from this link how to handle iframe in selenium
first you need to swich to the iframe.
for that you need to write below code after your Thread.sleep(3000);
find the iframe name from your html source.
driver.switchTo().frame("notification-frame-~2514428c7");
driver.findElement(By.xpath("//i[@class='wewidgeticon we_close']")).click();
By using this you can close your html popup.
Alert Handling in Selenium Webdriver
Based on the original question and the subsequent comments, I suspect what you're dealing with is a browser pop up window and not an alert. So this won't work
driver.switchTo().alert().accept();
You need to use window handles
Set<String> handles = driver.getWindowHandles();
Iterator<String> windows = handles.iterator();
String parent = windows.next();
String child = windows.next();
driver.switchTo().window(child);
driver.findElement(By.xpath("insert xpath to OK button")).click();
driver.switchTo().window(parent);
//continue with steps on parent window
Note: ensure that you add the required synchronization to the code snippet above
How to handle intermittent alert in Selenium WebDriver?
JavascriptExecutor worked for you. Just take care that you should execute it before clicking the event which invoke alert.
((JavascriptExecutor) driver).executeScript("window.confirm = function(msg) { return true; }");
Note :- do not use it after clicking on event which invoke alert confirmation box. Above code by default set the confirmation box as true means you are accepting/click on ok on all confirmation box on that page if invoked
Hope it will help you :)
Related Topics
How to Use a Custom Font in Java
Listener Placement Adhering to the Traditional (Non-Mediator) MVC Pattern
Swingutilities.Invokelater() Why Is It Needed
Map Enum in JPA with Fixed Values
Deep Clone Utility Recommendation
Does Java Evaluate Remaining Conditions After Boolean Result Is Known
Java "User.Dir" Property - What Exactly Does It Mean
Bypass Generatedvalue in Hibernate (Merge Data Not in Db)
Clone() VS Copy Constructor VS Factory Method
How to Use "." as the Delimiter with String.Split() in Java
How Do Synchronized Static Methods Work in Java and How to Use It for Loading Hibernate Entities
How to Obtain Localdatetime from Temporalaccessor When Parsing Localdatetime (Java 8)
How to Perform String Diffs in Java
How to Set an Image as a Background for Frame in Swing Gui of Java