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,490 points
2,450 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,910 points
1,158 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,460 points
8,156 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,460 points
2,491 views
0 votes
2 answers

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

Hi , we have inbuilt method Maximize(). driver.Manage().Wind ...READ MORE

answered Sep 6, 2020 in Selenium by Sri
• 3,190 points
16,035 views
0 votes
2 answers

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,500 points
13,674 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,143 views
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,910 points
7,221 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,875 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
3,810 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP