Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
106
rated 0 times [  107] [ 1]  / answers: 1 / hits: 42457  / 10 Years ago, thu, january 8, 2015, 12:00:00

I am not sure whether selenium webdriver can handle Javascript alert/pop-up window.



I have a scenario like

1. User uploads a xls file and click on upload button

2. Alert/Pop-up window will be displayed . Click OK on window



Am able to automate the above scenario but the Alert/pop-up window is displayed while running the scripts.



Is their anyway workaround that we can handle javascript alert/pop-up window?


More From » java

 Answers
7

You can also try waiting for the alert to appear and then accepting it.



Below is the code for that (after the upload button is clicked):



try{
//Wait 10 seconds till alert is present
WebDriverWait wait = new WebDriverWait(driver, 10);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());

//Accepting alert.
alert.accept();
System.out.println(Accepted the alert successfully.);
}catch(Throwable e){
System.err.println(Error came while waiting for the alert popup. +e.getMessage());
}

[#68279] Monday, January 5, 2015, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bradenc

Total Points: 75
Total Questions: 96
Total Answers: 129

Location: Burundi
Member since Thu, Feb 10, 2022
2 Years ago
;