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 in Selenium by Usman
37 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 by Abha
• 24,740 points

Related Questions In Selenium

+2 votes
1 answer

How can we handle authentication popup in Selenium WebDriver using Java

The Alert Method, authenticateUsing() lets us skip ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,650 points
7,553 views
0 votes
1 answer
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,090 points
762 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
1,004 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
715 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 in Selenium by Abha
• 24,740 points
70 views
0 votes
1 answer