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 26, 2019 in Selenium by Usman
477 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 26, 2019 by Abha
• 27,930 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 30 in Selenium by Sri
• 2,970 points
17,775 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,510 points
3,535 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

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

answered Aug 31 in Selenium by Sri
• 2,970 points
4,540 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
2,596 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 2 in Selenium by Sri
• 2,970 points
2,865 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 2, 2019 in Selenium by Abha
• 27,930 points
2,354 views
0 votes
1 answer