Forum: Ruby watir related question

Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-05 11:33
hi,

I have written the piece of code which is given in
"http://watirwebdriver.com/mobile-devices/"


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
end


It's printing

Watir::HTMLElement
Watir::HTMLElement
Watir::HTMLElement
Watir::HTMLElement
.
.
.
.

all elements are Watir::HTMLElement, If this is the case, how can I
locate the element in using my code?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-06 23:57
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
e.attribute_value("class")
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-07 08:03
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.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-07 08:41
hi Joel,

It's working perfectly in scite editor, But If I paste this line in my
Eclipse
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?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-07 21:10
that form of hash syntax started with 1.9.2, so you're probably using an
older parser within Eclipse.
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-08 06:37
Is there any way to change this Joel?
14b5582046b4e7b24ab69b7886a35868?d=identicon&s=25 Joel Pearson (virtuoso)
on 2014-08-08 19:21
Use the rocket syntax if you're using an old parser

{ class: "ui-btn-text",text: "Get InstantQuote" }

becomes

{ :class => "ui-btn-text", :text => "Get InstantQuote" }
Cc704ce316e72af824ccd38cfa53104b?d=identicon&s=25 Raja Gopalan (arc)
on 2014-08-08 19:39
This is Great!!!
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.