Steps to reproduce:
- Open the HTML page.
- Execute snippet in console.
Browsers:
- Firefox 38.3.0.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Documentation by YARD 0.8.7.3</title> | |
<style type="text/css"> | |
body { | |
padding: 0 20px; | |
font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; |
# I'm running OS X and I need to develop and test Vagrant features | |
# which are specific to Linux-only, i.e. I need "physical" Linux machine. | |
# I've finally stuck with creating DigitalOcean VM and installing | |
# everything necessary for development there. It's magical | |
# Vagrant-powered Vagrant-development Vagrantfile. | |
# | |
# First, start the VM which will be the host: | |
# $ vagrant up host --provider=digital_ocean | |
# | |
# Now, you can start VM in VM which will be used for Vagrant testing: |
require 'watir-webdriver' | |
browser = Watir::Browser.new | |
browser.goto 'http://google.com' | |
browser.button(name: 'btnK').disabled? | |
#=> false | |
browser.button(name: 'btnK').enabled? | |
#=> true |
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 |
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 |
❯ 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>' |
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 |
caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true) | |
driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps) | |
browser = Watir::Browser.new(driver) |
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 } |