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.

*<a onfocus="javascript:setFocus('ok')" onblur="javascript:setFocus('')"
onmouseout="window.status='';return true;"
onmouseover="window.status='';return true;" href="javascript:doSubmit()"> ...
</a>*

Thank you

Ruby Student

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: '<whatever the link text is>').click

From: Ruby Student <ruby.student@gmail.com>
To: ruby-talk ML <ruby-talk@ruby-lang.org>
Date: 03/03/2014 03:34 PM
Subject: Need help using watir-webdriver to auto login and screen

scraping

···

"ruby-talk" <ruby-talk-bounces@ruby-lang.org> wrote on 03/03/2014 03:33:13 PM:

Sent by: "ruby-talk" <ruby-talk-bounces@ruby-lang.org>

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&quot;
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.

<a onfocus="javascript:setFocus('ok')" onblur="javascript:setFocus('')
" onmouseout="window.status='';return true;"
onmouseover="window.status='';return true;" href="javascript:doSubmit()
"> … </a>

Thank you

Ruby Student

Well, it seems that there's no button (no <input type="button">), but
instead there is a link (<a>). 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&quot;
b.text_field(:name => 'CAMUsername').set("test")
b.text_field(:name => 'CAMPassword').set("test")
b.link(:href => 'javascript:doSubmit()').click
puts b.url

Jesus.

···

On Mon, Mar 3, 2014 at 9:33 PM, Ruby Student <ruby.student@gmail.com> wrote:

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&quot;
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.

<a onfocus="javascript:setFocus('ok')" onblur="javascript:setFocus('')"
onmouseout="window.status='';return true;"
onmouseover="window.status='';return true;" href="javascript:doSubmit()"> ...
</a>

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 Jesús for your help.

···

On Mon, Mar 3, 2014 at 3:45 PM, Jesús Gabriel y Galán < jgabrielygalan@gmail.com> wrote:

On Mon, Mar 3, 2014 at 9:33 PM, Ruby Student <ruby.student@gmail.com> > wrote:
>
> 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&quot;
> 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.
>
> <a onfocus="javascript:setFocus('ok')" onblur="javascript:setFocus('')"
> onmouseout="window.status='';return true;"
> onmouseover="window.status='';return true;"
href="javascript:doSubmit()"> ...
> </a>

Well, it seems that there's no button (no <input type="button">), but
instead there is a link (<a>). 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&quot;
b.text_field(:name => 'CAMUsername').set("test")
b.text_field(:name => 'CAMPassword').set("test")
b.link(:href => 'javascript:doSubmit()').click
puts b.url

Jesus.

--
Ruby Student