Watir - finding element in form

Discussion in 'Ruby' started by Phil Mcdonnell, May 26, 2010.

  1. I'm trying to use Watir to log into a page. I can't seem to find the
    login button in order to click on it. From the Watir examples I've read
    it seems I need the following code:

    browser = Watir::Safari.new
    browser.goto @login_page
    browser.text_field:)name, 'UserID').set(ARGV[0])
    browser.text_field:)name, 'Password').set(ARGV[1])
    browser.button:)alt, 'Login').click

    However, the final line doesn't do anything. Note, the text_field lines
    do correctly set the username and password. Any idea how to fix this?

    Here's the relavent html:

    <FORM NAME="frmLogon"
    ACTION="/myca/logon/us/action?request_type=LogLogonHandler&location=us_logon1"
    METHOD="POST" onkeypress="formSub(event)">

    ... lots of stuff ...

    <input type='image' src ="/myca/logon/us/shared/images/btn_login.gif"
    alt="Login" style="margin-top:5;margin-left:20;margin-bottom:22" border
    = "0" tabIndex='5' onClick="javascript:loginNow();return false;">


    ... lots of stuff ...

    </FORM>

    Also, the full site is here:
    https://online.americanexpress.com/...ountSummary&us_nu=logincontrol&Info=CUExpired
    --
    Posted via http://www.ruby-forum.com/.
    Phil Mcdonnell, May 26, 2010
    #1
    1. Advertising

  2. Phil Mcdonnell

    Dimitri Df Guest

    You could try to use :index to find the form you want and submit it that
    way.
    example: browser.form:)index, 1).submit
    Or by using :name of the form
    example: browser.form:)name, 'frmLogon').submit

    Phil Mcdonnell wrote:
    > I'm trying to use Watir to log into a page. I can't seem to find the
    > login button in order to click on it. From the Watir examples I've read
    > it seems I need the following code:
    >
    > browser = Watir::Safari.new
    > browser.goto @login_page
    > browser.text_field:)name, 'UserID').set(ARGV[0])
    > browser.text_field:)name, 'Password').set(ARGV[1])
    > browser.button:)alt, 'Login').click
    >
    > However, the final line doesn't do anything. Note, the text_field lines
    > do correctly set the username and password. Any idea how to fix this?
    >
    > Here's the relavent html:
    >
    > <FORM NAME="frmLogon"
    > ACTION="/myca/logon/us/action?request_type=LogLogonHandler&location=us_logon1"
    > METHOD="POST" onkeypress="formSub(event)">
    >
    > ... lots of stuff ...
    >
    > <input type='image' src ="/myca/logon/us/shared/images/btn_login.gif"
    > alt="Login" style="margin-top:5;margin-left:20;margin-bottom:22" border
    > = "0" tabIndex='5' onClick="javascript:loginNow();return false;">
    >
    >
    > ... lots of stuff ...
    >
    > </FORM>
    >
    > Also, the full site is here:
    > https://online.americanexpress.com/...ountSummary&us_nu=logincontrol&Info=CUExpired

    --
    Posted via http://www.ruby-forum.com/.
    Dimitri Df, May 26, 2010
    #2
    1. Advertising

  3. On Tue, May 25, 2010 at 11:24 PM, Phil Mcdonnell
    <> wrote:
    > I'm trying to use Watir to log into a page. =A0I can't seem to find the
    > login button in order to click on it. =A0From the Watir examples I've rea=

    d
    > it seems I need the following code:


    > browser.button:)alt, 'Login').click
    >
    > However, the final line doesn't do anything.


    > Here's the relavent html:


    > =A0<input type=3D'image' src =3D"/myca/logon/us/shared/images/btn_login.g=

    if"
    > alt=3D"Login" style=3D"margin-top:5;margin-left:20;margin-bottom:22" bord=

    er
    > =3D "0" tabIndex=3D'5' onClick=3D"javascript:loginNow();return false;">


    I've never used Watir, but a quick glance at the API has this for the
    "button" method --

    "Used to access a button element. Usually an <input type =3D "button"> HTML=
    tag."

    Which the form snippet above clearly is not. So I'm not sure why you
    expect this to work. :)

    Either you have to find the appropriate method, or select that input
    element some other way.

    HTH,
    --=20
    Hassan Schroeder ------------------------
    twitter: @hassan
    Hassan Schroeder, May 26, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rod  Snyder

    moving from form element to form element

    Rod Snyder, May 29, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    397
    Vidar Petursson
    May 29, 2004
  2. HANM
    Replies:
    2
    Views:
    691
    Joseph Kesselman
    Jan 29, 2008
  3. Lisa Cook
    Replies:
    1
    Views:
    118
    Lisa Cook
    Jan 17, 2008
  4. Anukul Singhal
    Replies:
    1
    Views:
    157
    Charley Baker
    May 15, 2008
  5. micako
    Replies:
    2
    Views:
    112
    micako
    Jan 12, 2011
Loading...

Share This Page