# Watir - finding element in form

**URL:** <https://www.ruby-forum.com/t/watir-finding-element-in-form/189182>\
**Category:** Ruby\
**Created:** [May 26, 2010, 8:24am UTC](https://www.ruby-forum.com/t/watir-finding-element-in-form/189182 "2010-05-26T08:24:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![csitol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e4f/32.png) [@csitol](https://www.ruby-forum.com/u/csitol)\
**Post date:** [May 26, 2010, 8:24am UTC](https://www.ruby-forum.com/t/watir-finding-element-in-form/189182/1 "2010-05-26T08:24:22Z")

</div>

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:

… lots of stuff …

… lots of stuff …

Also, the full site is here:  
[https://online.americanexpress.com/myca/logon/us/action?request\_type=LogonHandler&Face=en\_US&DestPage=https://www99.americanexpress.com/myca/acctsumm/us/action%3Frequest\_type%3Dauthreg\_acctAccountSummary%26us\_nu%3Dlogincontrol&Info=CUExpired](https://online.americanexpress.com/myca/logon/us/action?request_type=LogonHandler&Face=en_US&DestPage=https://www99.americanexpress.com/myca/acctsumm/us/action%3Frequest_type%3Dauthreg_acctAccountSummary%26us_nu%3Dlogincontrol&Info=CUExpired)

---

<div class="post-metadata">

**Author:** ![csitol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e4f/32.png) [@csitol](https://www.ruby-forum.com/u/csitol)\
**Post date:** [May 26, 2010, 4:56pm UTC](https://www.ruby-forum.com/t/watir-finding-element-in-form/189182/2 "2010-05-26T16:56:05Z")

</div>

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:
> 
> … lots of stuff …
> 
> … lots of stuff …
> 
> Also, the full site is here:  
> [Login](https://online.americanexpress.com/myca/logon/us/action?request_type=LogonHandler&Face=en_US&DestPage=https://www99.americanexpress.com/myca/acctsumm/us/action%3Frequest_type%3Dauthreg_acctAccountSummary%26us_nu%3Dlogincontrol&Info=CUExpired)

---

<div class="post-metadata">

**Author:** ![csitol](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a88e4f/32.png) [@csitol](https://www.ruby-forum.com/u/csitol)\
**Post date:** [May 26, 2010, 7:50pm UTC](https://www.ruby-forum.com/t/watir-finding-element-in-form/189182/3 "2010-05-26T19:50:14Z")

</div>

On Tue, May 25, 2010 at 11:24 PM, Phil Mcdonnell  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.button(:alt, ‘Login’).click
> 
> However, the final line doesn’t do anything.

> Here’s the relavent html:

> 

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   
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,
