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' | |
browser = Watir::Browser.new | |
browser.goto 'http://google.com' | |
browser.button(name: 'btnK').disabled? | |
#=> false | |
browser.button(name: 'btnK').enabled? | |
#=> 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 'benchmark' | |
require 'selenium-webdriver' | |
old_locator = ".//input[not(@type) or (@type!='file' and @type!='radio' and @type!='checkbox' and @type!='submit' and @type!='reset' and @type!='image' and @type!='button' and @type!='hidden' and @type!='datetime' and @type!='date' and @type!='month' and @type!='week' and @type!='time' and @type!='datetime-local' and @type!='range' and @type!='color')]" | |
new_locator = ".//input[not(@type) or (translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='file' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='radio' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='checkbox' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='submit' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='reset' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')!='image' and translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','ab |
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' | |
browser = Selenium::WebDriver.for :firefox | |
browser.get 'http://www.commonfloor.com/' | |
# first open up drop down | |
browser.find_element(xpath: '//div[@id="city_chzn"]/a').click | |
# now click necessary element (note that it won't work with selenium 2.27) | |
browser.find_element(xpath: '//div[@id="city_chzn"]//li[contains(.,"Bangalore")]').click |
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
❯ ruby selenium_scroll_issue.rb | |
/Users/p0deje/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.27.1/lib/selenium/webdriver/remote/bridge.rb:516:in `getElementLocationOnceScrolledIntoView': undefined method `[]' for nil:NilClass (NoMethodError) | |
from /Users/p0deje/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.27.1/lib/selenium/webdriver/common/element.rb:215:in `location_once_scrolled_into_view' | |
from selenium_scroll_issue.rb:5:in `<main>' |
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' | |
begin | |
browser = Watir::Browser.new | |
browser.goto "data:text/html,#{DATA.read}" | |
rows = browser.table.rows | |
rows.each do |tr| | |
p tr.td(index: 2).text | |
end | |
ensure |
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
caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true) | |
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps) | |
browser = Watir::Browser.new(driver) |
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 Page | |
# | |
# Waits until DOM subtree changes in element. | |
# | |
# @param [Watir::Element] element | |
# | |
def wait_for_dom(element) | |
browser.execute_script File.read('wait_for_dom.js'), element | |
Watir::Wait.until { browser.execute_script('return Watir.DOMReady;').to_i == 0 } |
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
browser = Watir::Browser.start "data:text/html,<textarea />" | |
browser.text_field.exists? #=> false | |
browser.text_field(:index => 0).exists? #=> true | |
browser.text_fields.size #=> 1 | |
browser.textarea.exists? #=> 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
➜ bundle exec rake html5:generate | |
rake aborted! | |
invalid byte sequence in US-ASCII | |
/Users/p0deje/Development/watir-webdriver/vendor/bundle/ruby/1.9.1/gems/treetop-1.4.12/lib/treetop/compiler/grammar_compiler.rb:34:in `gsub!' | |
/Users/p0deje/Development/watir-webdriver/vendor/bundle/ruby/1.9.1/gems/treetop-1.4.12/lib/treetop/compiler/grammar_compiler.rb:34:in `block in load' | |
/Users/p0deje/Development/watir-webdriver/vendor/bundle/ruby/1.9.1/gems/treetop-1.4.12/lib/treetop/compiler/grammar_compiler.rb:32:in `open' | |
/Users/p0deje/Development/watir-webdriver/vendor/bundle/ruby/1.9.1/gems/treetop-1.4.12/lib/treetop/compiler/grammar_compiler.rb:32:in `load' | |
/Users/p0deje/Development/watir-webdriver/vendor/bundle/ruby/1.9.1/gems/polyglot-0.3.3/lib/polyglot.rb:47:in `load' | |
/Users/p0deje/Development/watir-webdriver/vendor/bundle/ruby/1.9.1/gems/polyglot-0.3.3/lib/polyglot.rb:66:in `rescue in require' | |
/Users/p0deje/Development/watir-webdriver/vendor/bundle/ruby/1.9.1/gems/polyglot-0.3.3/lib/polyglot.rb:63:in `require' |
OlderNewer