Forms
Forms aren't visible through the browser, but are used a lot in web applications. To find them, look at the HTML source for <form> 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 <input type="submit"> HTML tag. Common attributes are id, name and value. For complete list see Methods Supported by Element.
What you see in the web browser:
This is the tag in the HTML source:
<form>
<input type="submit" id="one" value="Submit" />
</form>
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 <form> HTML tag. Common attributes are id, name, action and method. For complete list see Methods Supported by Element.
What you see in the web browser:
This is the tag in the HTML source:
<form id="one" name="loginform" action="login" method="get">
<input />
</form>
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