Vous êtes sur la page 1sur 16

S.

No

Task

open new instance of


driver

open URL

get()

Get Current URL

getCurrentUrl()

Get Title of Current web


page

getTitle()

Find Elements

findElements()

Find Element using name

findElement()

Find Elements using ID

findElements()

Find Element using path

findElement()

Clicking on any element or


button of webpage

10
11

12

Methods

Selecting the value


Typing text in text box or
text area.
Store text of targated web
element

getText()

13

Applying implicit wait in


web driver

implicitlyWait()

14

Wait for Title

implicitlyWait()

15

Drop down selection using


value

16

Drop down selection using


INDEX

17

Drop down selection using


Visible Text

18

Deselect using value

19

Deselect using INDEX

20

Deselect Using Visible Text

21

Deselect All

22

Navigate to URL

navigate().to

23

Navigate back

navigate().back();

24

Navigate forward

26

Capturing entire page


screenshot

27

Generating mouse hover


event - Menu

25

Verify if element is present

findElements();

28

Verify if element is
enabled or disabled

isEnabled();

29

Submit the form

submit()

30

store alert

31
32

accept alert
dismiss alert
Type text in Prompt
message

33
34
35
36
37
38
39
40
41

To Clear the text from text


field

42
43
44
45
46
47
48
49

Command
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();

driver.get("http:google.com")

driver.getCurrentUrl()

String title = driver.getTitle();

driver.findElement(By.name("q"));
driver.findElement(By.name("passwd"));
driver.findElement(By.id("passwd-id"));
driver.findElement(By.xpath("//input[@id=passwd-id]"));

driver.findElement(By.id("submitButton")).click();
select.findElements(By.tagName("option"));
driver.findElement(By.name("fname")).sendKeys("My First Name");

String dropdown =
driver.findElement(By.tagName("select")).getText();

driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

WebDriverWait wait = new WebDriverWait(driver, 15);


wait.until(ExpectedConditions.titleContains(": MyTest"));

Select listbox = new


Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByValue("Italy");
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.selectByIndex(0);
Select mydrpdwn = new Select(driver.findElement(By.id("Carlist")));
mydrpdwn.selectByVisibleText("Audi");
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByValue("Mexico");
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByIndex(5);
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectByVisibleText("Russia");
Select listbox = new
Select(driver.findElement(By.xpath("//select[@name='FromLB']")));
listbox.deselectAll();
driver.navigate().to("http://only-testingblog.blogspot.com/2014/01/textbox.html");
driver.navigate().back();
driver.navigate().forward();

File screenshot =
((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
e.g. FileUtils.copyFile(screenshot, new File("D:\\screenshot.jpg"));

Actions actions = new Actions(driver); WebElement moveonmenu =


driver.findElement(By.xpath("//div[@id='menu1']/div"));
actions.moveToElement(moveonmenu); actions.perform();

Boolean iselementpresent =
driver.findElements(By.xpath("//input[@id='text2']")).size()!= 0;

boolean fname =
driver.findElement(By.xpath("//input[@name='fname']")).isEnabled(
); System.out.print(fname);

driver.findElement(By.xpath("//input[@name='Company']")).submit(
);

String myalert = driver.switchTo().alert().getText();

driver.switchTo().alert().accept();
driver.switchTo().alert().dismiss();
driver.switchTo().alert().sendKeys("This Is John");
driver.find_element(:id,'airOrigin').send_keys [:control, 'a'], :space

Description/Purpose
Open the URL in Chrome or Mozilla
It will load a new web page in the current browser window. This is
done using an http get operation, and the method will block until
the load is complete. The command takes a single string type
parameter that is usually a URL of application under test
Parameters: URL - The URL to load and it should be a fully qualified
URL
The command is used to retrieve the URL of the webpage the user is
currently accessing
The command doesnt require any parameter

Sometimes in your test case, you needs to store your software web
application page title to compare it with expected page title
The command is used to retrieve the title of the webpage the user is
currently working on.

Find all elements within the current page using the given
mechanism
Find the first WebElement using the given method.
Find all elements within the current page using the given
mechanism
Find the first WebElement using the given method.

This syntax will click on targeted element in webdriver


To select the value

The command is used to retrieve the inner text


of the specified web element.
It is also one of the extensively used commands for verification of
messages, labels, errors etc displayed
on the web pages.

some elements takes some time to appear on software web


application page when browser is loading the page. In this case,
sometime your webdriver test will fail if you have not applied
Implicit wait in your test case. If implicit wait is applied in your test
case then webdriver will wait for specified amount of time if
targeted element not appears on page.

In some special cases where implicit wait is not able to handle your
scenario then in that case you need to use explicit waits in your
software automation test cases.
If you have a scenario where you need to wait for title then you can
use titleContains(java.lang.String title) with webdriver wait. You
need to provide some part of your expected software web
application page title with this condition

Select from the dropdown list

Select from the dropdown list

Select from the dropdown list

If you wants to navigate on specific software web application page


or URL in between your software test then you can use
driver.navigate().to command
This command is useful to go back on previous page. Same as we
are clicking browser back button. You can use this command as
bellow.
Same as we are clicking on forward button of browser.

It is very basic required thing in software automation tools to


capture screenshot on test case failure or whenever required during
test case execution.

To generate mouse hover event in webdriver software testing tool,


We can use advanced user interactions API constructor "Actions"
with "moveToElement" method

Some times you need to verify the presence of element before


taking some action on software web application page
frequently you need to verify that your targeted element is enabled
or disabled on page of software web application before performing
action on it.
isEnabled() webdriver method will verify and return true if specified
element is enabled. Else it will return false.
You will find many forms In any software web application like
Contact Us form, New User Registration Form, Inquiry Form, LogIn
Form etc.
submit() method works same as clicking on submit button
You can use .click() method to click on any button of software web
application. Means element's type = "button" or type = "submit",
.click() method will works for both.

Alerts, Confirmation and Prompts are very commonly used elements


of any software webpage. Selenium webdriver software testing tool
has Its own Alert Interface to handle all above different popups.
Alert Interface has different methods like accept(), dismiss(),
getText(), sendKeys(java.lang.String keysToSend) and we can use all
these methods to perform different actions on popups.
To accept the alert message
To dismiss the alert message
To type text In text box of prompt popup

Output
Open the browser specified by the user

Open the specified URL in the browser

The URL of the page currently loaded in


the browser.
This command returns a string value
The title of the current page, with leading
and trailing white space stripped, or null
if one is not already set.
A null string is returned if the webpage
has no title. The command doesnt
require any parameter and returns a
trimmed string value
A list of all WebElements, or an empty list
if nothing matches
NoSuchElementException - it will return
exception if no matching elements are
found
A list of all WebElements, or an empty list
if nothing matches
NoSuchElementException - it will return
exception if no matching elements are
found

The command doesnt require any


parameter and returns a string value

This syntax will force webdriver to wait


for 15 second if element not found on
page of software web application.

In the command example:


": MyTest" is my web page's expected
title and 15 seconds is max waiting time
to appear title on web page. If title will
not appears within 15 seconds due to the
any reason then your test case will fails
with timeout error

It will select value by value = "Italy".

It will select value by Index = "0" i.e. It


will select the 1st option
It will select value from drop down list
using visible text value = "Audi".
It will deselect option by value = Mexico
from list box
It will deselect option by Index = 5 from
list box.
It will deselect option by visible text =
Russia from list box.
It will remove all selections from list box
of software application's page.

It will capture page screenshot and


store it in your D: drive

This will only move mouse on targeted


element of software web application. It
will not perform click operation.
syntax will return true if element is
present on page of software web
application. Else it will return false
This will verify that element (text box)
fname is enabled or not. You can use it
for any input element

It will submit the form

This will store the alert text

This will store the alert text


This will dismiss the alert text