What is the best way to handle a Javascript popup using Selenium Webdriver?

0 votes
Can anyone suggest what is the best way to handle a JavaScript Pop-up using Selenium Webdriver?
May 10 in Selenium by Dimple
23 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

Hello Dimple, the simplest way to handle JavaScript popup/alert using selenium is by using the Alert interface. To access the popup/alert dialog in Selenium Webdriver, use the following line of code:

webDriver.switchTo().alert()

The alert interface provides following methods to handle/interact with such Javascript popups/dialogs:

  • accept(): To accept an popup/alert
  • dismiss(): To decline an popup/alert
  • getText(): To get the text written on the popup/alert
  • sendKeys(keysToEnter): To enter some text on the popup/alert's input box
answered May 10 by Pratibha
• 2,520 points

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

I tried to open a new website when a new tab is opened using Selenium Webdriver

Try this code: ArrayList<String> tabs = new ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
474 views
0 votes
1 answer
0 votes
1 answer

Is it possible to manually set the attribute value of a Web Element using Selenium?

Yes, its very much possible. You just ...READ MORE

answered May 8, 2018 in Selenium by king_kenny
• 3,590 points
3,245 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
65 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
438 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
51 views
0 votes
1 answer
0 votes
1 answer

What is Xpath and what are the types of it in Selenium Webdriver?

Hi Piyush, XPath is defined as XML path. It is ...READ MORE

answered May 8 in Selenium by Pratibha
• 2,520 points
19 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.