Handling JavaScript Alert window in Selenium WebDriver

0 votes
I uploaded an xls file and clicked on upload button. Alert popped out and click on Ok button.

But m I was able to automate the above scenario, but the Alert window is displayed while running the scripts.Is there anyway workaround that we can handle javascript alert/pop-up window?
Apr 10, 2018 in Selenium by Shubham
• 13,290 points
762 views

1 answer to this question.

0 votes

You should try using waits for alerts because to appear it on the screen and accept it .Below code will help u:

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());

}
answered Apr 10, 2018 by ghost
• 1,790 points

Related Questions In Selenium

0 votes
1 answer

Maximizing the browser window in Selenium WebDriver using C#

Check this first: http://code.google.com/p/selenium/issues/detail?id=174 You Can use the JavascriptExector as follows: public ...READ MORE

answered May 2, 2018 in Selenium by Samarpit
• 5,130 points
64 views
0 votes
1 answer

Handling print dialog in Selenium WebDriver

In Selenium WebDriver we are not able ...READ MORE

answered May 11, 2018 in Selenium by Meci Matt
• 9,420 points
1,065 views
0 votes
1 answer

Maximizing browser window in Selenium WebDriver using C#

You can use the JavascriptExector as follows: public void maximize() ...READ MORE

answered May 30, 2018 in Selenium by Meci Matt
• 9,420 points
351 views
0 votes
1 answer

How to open a browser window in full screen using Selenium WebDriver with C#

Simply Use this: driver.Manage().Window.Maximize(); READ MORE

answered Jun 7, 2018 in Selenium by Samarpit
• 5,130 points
3,067 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,070 points
438 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
788 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
431 views
0 votes
1 answer
0 votes
1 answer

Differences between Implicit wait Vs. Explicit wait in selenium webdriver

Implicit Wait - It instructs the web driver ...READ MORE

answered Apr 9, 2018 in Selenium by ghost
• 1,790 points
1,278 views