How can I handle Javascript Alert popup using Ruby Selenium webdriver

0 votes
How can I handle Javascript Alert popup using Ruby Selenium Webdriver?
Aug 27, 2019 in Selenium by Usman
1,506 views

1 answer to this question.

0 votes

Hey Usman, you can use driver.switch_to.alert method to handle the javascript alert popup. This method switches the focus from default window to Javascript alert popup, so that necessary action can be done. Checkout the following example to understand better:

driver = Selenium::WebDriver.for :firefox

driver.get 'http://the-internet.herokuapp.com/javascript_alerts'
driver.find_elements(css: 'button')[1].click

alert_popup = driver.switch_to.alert
alert_popup.accept

result = driver.find_element(id: 'result').text
expect(result).to eql('You clicked: Ok')
answered Aug 27, 2019 by Abha
• 28,120 points

Related Questions In Selenium

+2 votes
3 answers

How can we handle authentication popup in Selenium WebDriver using Java

1) By passing user credentials in URL. String ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
26,536 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
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
9,066 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
7,488 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,890 points
5,254 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
6,550 views
0 votes
1 answer

How can I send some data to a Prompt Alert box using Selenium Webdriver?

Hey Abhishek, you can use sendKeys() method ...READ MORE

answered Jul 3, 2019 in Selenium by Abha
• 28,120 points
7,515 views
0 votes
1 answer
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