Watir related question


I have written the piece of code which is given in

require ‘watir-webdriver’
require ‘webdriver-user-agent’
driver = UserAgent.driver(:browser => :chrome, :agent => :iphone,
:orientation => :landscape)
browser = Watir::Browser.new driver
browser.goto ‘tiffany.com

Once this page got opened, I started to print the elements type

b.elements.each do |e|
puts e.class

It’s printing


all elements are Watir::HTMLElement, If this is the case, how can I
locate the element in using my code?

Right click the target element in your browser and click “inspect” to
look at things like the class, id, name, etc. Then select that element
with code like: b.text_field(class: ‘thisclass’, id: ‘thisid’)

If you want to see the html class of an element, not its Ruby Class; use

hi Joel,

You taught me new way of identifying the elements,

I know b.text_field(:id,‘adc’) but I don’t know b.text_field(id: ‘adb’)
this way of identifying, thank you so much, this works for me.

hi Joel,

It’s working perfectly in scite editor, But If I paste this line in my
throws the syntax error

10: syntax error, unexpected ‘:’

b.span(class: “ui-btn-text”,text: “Get InstantQuote”).when_present.click

Any idea how to resolve this?

that form of hash syntax started with 1.9.2, so you’re probably using an
older parser within Eclipse.

Is there any way to change this Joel?

This is Great!!!

Use the rocket syntax if you’re using an old parser

{ class: “ui-btn-text”,text: “Get InstantQuote” }


{ :class => “ui-btn-text”, :text => “Get InstantQuote” }