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
• 12,150 points
582 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
45 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,400 points
626 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,400 points
204 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
1,858 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,030 points
60 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
432 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
49 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
982 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.