This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context 'when set to true' do | |
before do | |
Watir.always_locate = true | |
browser.goto WatirSpec.url_for('removed_element.html', :needs_server => true) | |
end | |
it '#exists? relocates the element when it is stale' do | |
element = browser.div(:id => "text") | |
expect(element.exists?).to be true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'watir-webdriver' | |
b = Watir::Browser.new | |
b.goto "#{your_url}" | |
# Match first span with class 'title' | |
b.span(class: 'title') | |
# Array of spans matching class 'title' | |
b.spans(class: 'title') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'selenium-webdriver' | |
first_window = File.open('window1.html', 'w').tap {|f| f.puts "<html><head><title><Window1</title></head><body><p>Click <a id='open' href='#' onclick='window.open(\"window2.html\")'>here</a></body></html>" } | |
first_window.close | |
File.open('window2.html', 'w').tap {|f| f.puts "<html><head><title>window1</title></head><body><p>Click <a id='close' href='#' onclick=\"window.close()\">close</a></p></body></html>" }.close | |
driver = Selenium::WebDriver.for :chrome | |
driver.navigate.to "file://#{File.expand_path(File.dirname(__FILE__))}/#{first_window.path}" | |
driver.first(id: 'open').click | |
driver.switch_to.window(driver.window_handles.last) | |
driver.first(id: 'close').click | |
#driver.window_handles ### If you un-comment out this line, the test will pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def window(id) | |
if block_given? | |
begin | |
original = @bridge.getCurrentWindowHandle | |
rescue Selenium::WebDriver::Error::NoSuchWindowError | |
original = nil | |
end | |
@bridge.switchToWindow id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it "should not throw error when running error checks on closed window" do | |
browser.close | |
client = Selenium::WebDriver::Remote::Http::Default.new | |
client.timeout = 5 | |
browser = Watir::Browser.start(WatirSpec.url_for("window_switching.html"), :chrome, http_client: client) | |
browser.a(:id => "open").click | |
window = browser.window(:title => "closeable window") | |
window.use | |
browser.a(:id => "close").click | |
expect { browser.driver.current_url }.to_not raise_error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/home/titus/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:519:in `getElementAttribute' | |
/home/titus/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/common/element.rb:98:in `attribute' | |
/home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:186:in `fetch_value' | |
/home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:192:in `block in matches_selector?' | |
/home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:191:in `each' | |
/home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:191:in `all?' | |
/home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:191:in `matches_selector?' | |
/home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/button_locator.rb:66:in `matches_selector?' | |
/home/titus/workspace/watir-webdriver/lib/watir-webdriver/locators/element_locator.rb:152:in `block in wd_find_by_r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GoogleHome | |
def initialize driver | |
@driver = driver | |
end | |
def goto | |
go_to "http://google.com" | |
return self | |
end | |
def search_field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include UtilityModule | |
initialize_test | |
go_to "http://google.com" | |
search_term = "Cheese!" | |
submit_text({:name => "q"}, search_term) | |
wait_for_element_present(:id => "search") | |
raise unless get_title.include?(search_term.downcase) | |
end_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'selenium-webdriver' | |
driver = Selenium::WebDriver.for :firefox | |
driver.get "http://google.com" | |
element = driver.find_element(:name => "q") | |
element.send_keys "Cheese!" | |
element.submit | |
wait = Selenium::WebDriver::Wait.new(:timeout => 10) | |
wait.until { driver.title.downcase.start_with? "cheese!" } | |
driver.quit |
NewerOlder