How can I handle Ja...
 
Notifications
Clear all

How can I handle Javascript Alert popup using Ruby Selenium webdriver  

  RSS

Sathish Kumar
(@sathish)
Member Moderator
Joined: 4 months ago
Posts: 1203
31/03/2021 11:02 am  

How can I handle Javascript Alert popup using Ruby Selenium Webdriver?


Quote
Abhijith
(@abhijith)
Noble Member
Joined: 4 months ago
Posts: 1161
31/03/2021 11:02 am  

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')

ReplyQuote
Share: