Skip to content

Instantly share code, notes, and snippets.

@tourdedave
Created May 15, 2014 18:38
Show Gist options
  • Select an option

  • Save tourdedave/16cff54b35942e90629c to your computer and use it in GitHub Desktop.

Select an option

Save tourdedave/16cff54b35942e90629c to your computer and use it in GitHub Desktop.
require 'selenium-webdriver'
require 'rspec-expectations'
include RSpec::Matchers
driver = Selenium::WebDriver.for :firefox
driver.get 'http://the-internet.herokuapp.com/javascript_alerts'
driver.find_elements(css: 'button')[1].click
# to click the second button, [0] would click the first, and [2] (or [-1]) would click the last one
popup = driver.switch_to.alert
popup.accept
result = driver.find_element(id: 'result').text
expect(result).to eq('You clicked: Ok')
driver.quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment