0% found this document useful (0 votes)
41 views

Accessing Forms in Webdriver HTML

Selenium accessing forms in webdriver

Uploaded by

Aravind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Accessing Forms in Webdriver HTML

Selenium accessing forms in webdriver

Uploaded by

Aravind
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Home

Testing

SAP

Web

Live Projects

Accessing Forms using Selenium WebDriver


In this tutorial , we will
learn how to access
forms and its elements
using Webdriver

Accessing Form
Elements
Input Box

Must Learn!

Blog

Search
Search for...

Selenium training class


webdriverguru.com

Input boxes refer to


either of these two
types:
1. Text Fields- text boxes that accept typed values and show them as
they are.
2. Password Fields- text boxes that accept typed values but mask
them as a series of special characters (commonly dots and
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

5 weeks automation boot camp


automation engineer fast

SoapUI WebService
Testing

Web Load Testing Too


pdfcrowd.com

asterisks) to avoid sensitive values to be displayed.

Load Testing 101

Attention Automation P

Download Free Audiob

Test Automation Softw

Free C# Code Generat


Entering Values in Input Boxes

Best Password Manag

The sendKeys() method is used to enter values into input boxes.

Selenium
Tutorials
1) Introduction
2) Install IDE &

Deleting Values in Input Boxes

FireBug
3) Introduction IDE

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

The clear() method is used to delete the text in an input box. This
method does not need any parameter. The code snippet below will
clear out the text "tutorial" in the User Name text box.

3) Introduction IDE
4) First Script
5) Locators
6) Enhancements
7) Intro WebDriver

Radio Button
Toggling a radio button on is done using the click() method.

8) Install
Webdriver
9) First WebDriver
Script
10) Forms &
Webdriver
11) Links & Tables
12) Keyboard
Mouse Events

Check Box
Toggling a check box on/off is also done using the click() method.
The code below will click on Facebook's "Keep me logged in" check
box twice and then output the result as TRUE when it is toggled on,
and FALSE if it is toggled off.
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

13) Selenium &


TestNG
14) Selenium Grid
15)
Parameterization
pdfcrowd.com

16) Cross Browser


Testing
17) All About Excel
in Selenium
18) Creating
Keyword & Hybrid
Frameworks
19) Page Object
Model & Page
Factory
20) PDF, Emails
and Screenshot of
Test Reports
21) Using
Contains, Sibling,
Ancestor to Find
Element
22) Core
Extensions
23) Sessions,
Parallel run and
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Dependency

Links

24) Handling Date

Links also are accessed by using the click() method.


Consider the below link found in Mercury Tours' homepage.

Time Picker
25)Using Apache
Ant with Selenium
26) Tutorial on
Log4j and
LogExpert with
Selenium
27) Maven &

You can access this link using linkText() or partialLinkText() together


with click(). Either of the two lines below will be able to access the
"Register here" link shown above.

Jenkins with
Selenium:
Complete Tutorial
28)Selenium with
HTMLUnit Driver &
PhantomJS
29)Database
Testing using
Selenium: Step by
Step Guide

Drop-Down Box
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Before we can control drop-down boxes, we must do following two


things :
1. Import the package org.openqa.selenium.support.ui.Select
2. Instantiate the drop-down box as a "Select" object in WebDriver
As an example, go to Mercury Tours' Registration page
(http://newtours.demoaut.com/mercuryregister.php) and notice the
"Country" drop-down box there.

Feedback
Your Feedback &
Ideas are very
important to us.
Please share your
suggestions here

Step 1
Import the "Select" package.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Step 2
Declare the drop-down element as an instance of the Select class. In
the example below, we named this instance as "drpCountry".

Step 3
We can now start controlling "drpCountry" by using any of the available
Select methods. The sample code below will select the option
"ANTARCTICA".

Selecting Items in a Multiple SELECT element


We can also use the selectByVisibleText() method in selecting
multiple options in a multi SELECT element. As an example, we will
take http://jsbin.com/osebed/2 as the base URL. It contains a dropdown box that allows multiple selections at a time.
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

The code below will select the first two options using the
selectByVisibleText() method.

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Select Methods
The following are the most common methods used on drop-down
elements.
Method
selectByVisibleText() and
deselectByVisibleText()
Example:
open in browser PRO version

Description
Selects/deselects the option
that displays the text matching
the parameter.
Parameter: The exactly
displayed text of a particular

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

displayed text of a particular


option
selectByValue() and
deselectByValue()
Example:

selectByIndex() and
deselectByIndex()
Example:

open in browser PRO version

Selects/deselects the option


whose "value" attribute
matches the specified
parameter.
Parameter: value of the
"value" attribute
Remember that not all dropdown options have the same
text and "value", like in the
example below.

Selects/deselects the option at


the given index.
Parameter: the index of the
option to be selected.

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

isMultiple()
Example:

deselectAll()
Example:

Returns TRUE if the drop-down


element allows multiple
selections at a time; FALSE if
otherwise.
Needs parameters needed

Clears all selected entries. This


is only valid when the dropdown element supports
multiple selections.
No parameters needed

Submitting a Form
The submit() method is used to submit a form. This is an alternative
to clicking the form's submit button.
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You can use submit() on any element within the form, not just on the
submit button itself.

When submit() is used, WebDriver will look up the DOM to know


which form the element belongs to, and then trigger its submit
function.

Summary
The table below summarizes the commands to access each type of
element discussed above.

Element

Command

Description

Input Box

sendKeys()

used to enter values onto

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Input Box

sendKeys()

used to enter values onto


text boxes

clear()

used to clear text boxes of


its current value

click()

used to toggle the element


on/off

Links

click()

used to click on the link and


wait for page load to
complete before proceeding
to the next command.

Drop-Down
Box

selectByVisibleText()/

selects/deselects an option
by its displayed text

Check Box,
Radio
Button,

deselectByVisibleText()
selectByValue()/
deselectByValue()

open in browser PRO version

selects/deselects an option
by the value of its "value"
attribute

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

selectByIndex()/
deselectByIndex()

Submit
Button

selects/deselects an option
by its index

isMultiple()

returns TRUE if the dropdown element allows


multiple selection at a time;
FALSE if otherwise

deselectAll()

deselects all previously


selected options

submit()

WebDriver allows selection of more than one option in a multiple


SELECT element.
To control drop-down boxes, you must first import the
org.openqa.selenium.support.ui.Select package and then create a
Select instance.
You can use the submit() method on any element within the form.
WebDriver will automatically trigger the submit function of the form
where that element belongs to.
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You Might Like


Top 20 Test Manager
Interview Questions

Free Business Analyst


Tutorial & Course

Download Test Plan


Template with Sample
Data

Big Data Testing:


Functional & Performance

Prev

Next

AROUND THE WEB

The Borgata

New Jersey Man Hits Record Jackpot at


open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Borgata Casino

RealDose Nutrition

Do You Know What Your Weight Loss


Type Is (And What It Means)? Take A
Test.

Brilliant Earth

7 Engagement Ring Trends of 2015

Instant Checkmate
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Have you ever Googled yourself? This


site reveals more info!
ALSO ON GURU99

Environment Variable in QTP (HP UFT) 1 comment

Seu primeiro pepino Script

Cmo utilizar Controller en LoadRunner 1 comment

Handling Date Time Picker using Selenium

4 Comments

Guru99

Share

Recommend

Join the discussion

Pandu Ranga G

8 months ago

Hi ,
Drop-Down Box:
i Couldn`t able to select an item using selectbyvalue nor selectbyvisibletext - please help me on this.
2

Reply Share

Vanniyaraja Karkuvel > Pandu Ranga G

8 months ago

Hi Pandu,
open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

As already stated by them its not available for all the web pages... selectByVisibleText & selectByindex w
helpful for all the webpages.


vivek

Reply Share

4 months ago

How to automate if a page a browse button to upload an image / file

Reply Share

Arjun > vivek

3 months ago

with the help of Robot class you can upload anything.


Robot robot=new Robot();
robot.keyPress(" keyEnvent");
robot.keyRelease(" keyEvent");

Subscribe

Reply Share

Add Disqus to your site

Privacy

comments powered by Disqus

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

About

Contact Us

About us
Corporate
Training
Jobs

Contact us
FAQ
Write For Us

Android
App

Copyright - Guru99 2015

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

Certifications Execute
online
ISTQB
Certification
MySQL
Certification
QTP
Certification
Testing
Certification

Execute Java
Online
Execute PHP
Online
Execute
PERL Online
Execute
Javascript
Execute
HTML
Execute
Python

Interesting!
Books to
Read!
Contest
Quiz

pdfcrowd.com

You might also like