Friday, April 9, 2010

watir: Forms: How to identify Forms in ruby scripting?

Forms aren't visible through the browser, but are used a lot in web applications. To find them, look at the HTML source for
tag. Watir can submit forms in a variety of ways.

Forms With Buttons

Watir can submit buttons on a web page contained in a form by looking at the attributes available in the HTML tag. Common attributes are id, name and value. For complete list see HTML Elements Supported by Watir.
What you see in the web browser:

This is the tag in the HTML source:

  "submit" id="one" value="Submit" />

id Attribute

This is the Watir code you need to click a button that will submit a form using the id attribute:
ie.button(:id, "one").click

Forms With No Buttons

There may be input fields on a web page, but no button to submit. Instead, they will allow you to hit Enter/Return on your keyboard. When there is no button to submit the data, we can just submit the form itself.
Watir can submit a form by looking at the attributes available in the
HTML tag. Common attributes are id, name, action and method. For complete list see HTML Elements Supported by Watir. What you see in the web browser:

This is the tag in the HTML source:
"one" name="loginform" action="login" method="get">
  

id Attribute

Watir code to submit the form using the id attribute:
ie.form(:id, "one").submit

name Attribute

Watir code to submit the form using the name attribute:
ie.form(:name, "loginform").submit

action Attribute

Watir code to submit the form using the action attribute:
ie.form(:action, "login").submit

method Attribute

Watir code to submit the form using the method attribute:
ie.form(:method, "get").submit

No comments:

Post a Comment