Need help using watir-webdriver to auto login and screen scraping

Hello team,

I am trying to login to a server using *watir-webdriver. *The final
objective is to scrape the screen and get certain information from it.
I started first by trying to login.
I am able to get the browser and fill in the USERID & PASSWORD to te
login
screen. However, I am having a hard time pressing the OK button in
order
to proceed to the main screen.
I tried all kinds of combinations and nothing worked so far.
The simple ruby code is listed below.

================================================
require ‘watir-webdriver’

b = Watir::Browser.new :firefox
b.goto “http://thehost/cognos8/cgi-bin/cognos.cgi
http://thehost/cognos8/cgi-bin/cognos.cgi

b.text_field(:name => ‘CAMUsername’).set(“test”)
b.text_field(:name => ‘CAMPassword’).set(“test”)
b.button(:value => ‘OK’).click
puts b.url
b.close

I am getting the following errors:

/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.8/lib/watir-webdriver/elements/element.rb:490:in
`assert_exists’: unable to locate element, using {:name=>“ok”,
:tag_name=>“button”} (Watir::Exception::UnknownObjectException)

  •    from
    

/usr/local/rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/watir-webdriver-0.6.8/lib/watir-webdriver/elements/element.rb:118:in
`click’*

  •    from checkPendingU1.rb:7:in `<main>'*
    

================================================

One last thing, I am also including what appears to be html code which I
got by running Inspector on firefox.

“Inspeting the element” in the JavaScript/html? code the following
appears
to be the code handling the OK button. But I don’t know what variable
to
use to click the button.


Thank you

Ruby S.

It can’t find the button because it doesn’t appear to be a button.
That snippet you gave is for a link.
Try something like:

b.a(text: ‘’).click

“ruby-talk” [email protected] wrote on 03/03/2014
03:33:13
PM:

From: Ruby S. [email protected]
To: ruby-talk ML [email protected]
Date: 03/03/2014 03:34 PM
Subject: Need help using watir-webdriver to auto login and screen
scraping

On Mon, Mar 3, 2014 at 9:33 PM, Ruby S. [email protected]
wrote:

The simple ruby code is listed below.
puts b.url
`click’


Well, it seems that there’s no button (no ), but
instead there is a link (). So you will have to find the link and
click it. I’ve never used watirwebdriver, but I’d guess it’d be
something like:

b = Watir::Browser.new :firefox
b.goto “
http://thehost/cognos8/cgi-bin/cognos.cgi
b.text_field(:name => ‘CAMUsername’).set(“test”)
b.text_field(:name => ‘CAMPassword’).set(“test”)
b.link(:href => ‘javascript:doSubmit()’).click
puts b.url

Jesus.

That was it! It was a link. I tried: b.link(:href =>
‘javascript:doSubmit()’).click and it work. I am one step closer to what
I
want to do.

Thank you both, Michael and Jess for your help.

On Mon, Mar 3, 2014 at 3:45 PM, Jess Gabriel y Galn <