Selenium WebDriver Methods

Selenium WebDriver Methods

Selenium WebDriver methods are used to perform operations on Browser as well as Web Elements(Objects, Ex: Links, Buttons, Edit boxes, Radio buttons, Check boxes etc...)

Using Element Locators as well as WebDriver methods nosotros tin ship away exercise Test cases.

1) get() Method
Description:
It opens specified url inwards the Browser window.

Syntax:
driverObject.get("URL")

Example:
driver.get("https://yahoo.com/");
--------------------------------------------
2) getTitle() Method
It returns championship of the Browser

Syntax:
String StringName = driverObject.getTitle();

Example:
String Title = driver.getTitle();
System.out.println(Title);
-----------------------------------------
3) getPageSource() Method
It returns HTML page source

Syntax:

String stringName = driverObject.getPageSource();

example:
String Pagesource = driver.getPageSource();
System.out.println(Pagesource);
-------------------------------------------
4) getCurrentUrl() method
It returns electrical flow url of the Browser

Syntax:

String stringName = driverObject.getCurrentUrl();

Example:

String url = driver.getCurrentUrl();
System.out.println(url);
--------------------------------------------
Browser navigation methods
5) navigate().to() Method
Loads a novel spider web page inwards the electrical flow browser window.

Syntax:

driverObject.navigate().to("url")

Example:

driver.get("https://google.com/");
driver.navigate().to("https://yahoo.com/");
---------------------------------   
6) navigate().back() Method
It moves a unmarried exceptional dorsum inwards the browser history.

Syntax:

driverObject.navigate().back()

example:

driver.get("https://google.com/");
driver.navigate().to("https://yahoo.com/");
driver.navigate().back();
--------------------------------------
7) navigate().forward() Method
It moves a unmarried exceptional forrad inwards the browser history.

Syntax:

driverObject. navigate().forward()

Example:

driver.get("https://google.com/");
driver.navigate().to("https://yahoo.com/");
driver.navigate().back();
driver.navigate().forward();
------------------------------------------------
8) navigate().refresh() method
It refresh the electrical flow spider web page

Syntax:

driverObject.navigate().refresh()

Example:

driver.get("https://google.com/");
driver.navigate().refresh();
--------------------------------------------------------
9) close() method
It closes the focused browser

Syntax:

driverObject.close();

Example:

driver.close();
----------------------------------
10) quit() method
It closess all browsers that opened past times Webdriver during execution.

Syntax:

driverObject.quit();

example:

driver.get("file:///E:/HTMLExamples/LoginPage.html");
driver.findElement(By.linkText("Sign In")).click();
driver.quit();
--------------------------------------------
Close Browser

UFT

Browser("title:=Google").Close

Selenium

driver.close();
------------------------
11) findelement() Method
It finds the start chemical cistron inside the electrical flow page using the given locator.

Syntax:

driverObject.findelement(By.locator("value").method();

WebElement elementName = driverObject.findelement(By.locator("value")
elementName.Method();

Example:

driver.findElement(By.id("gb_70")).click();

Or
   
WebElement push = driver.findElement(By.id("gb_70"));
button.click();
----------------------------------------
12) sendkeys()
Enters a value into Edit box

Syntax:

driverObject.findelement(By.locator("value").sendkeys("value");

example:

driver.findElement(By.id("Email")).sendKeys("India");

Or

WebElement editbox = driver.findElement(By.id("Email"));
editbox.sendKeys("India");   
----------------------------------------
13) clear() method
It clears the value from an Edit box

Syntax:

driverObject.findelement(By.locator("value").clear();

Example:

WebElement editbox = driver.findElement(By.id("Email"));
editbox.sendKeys("India");   
editbox.clear();

Or
driver.findElement(By.id("Email")).sendKeys("India");
driver.findElement(By.id("Email")).clear();
------------------------------------------------
14) click() method
It clicks an element

syntax:

driverObject.findelement(By.locator("value").click;

Example:

driver.findElement(By.id("next")).click();
--------------------------------------------------
15) isEnabled()
it checks weather condition the chemical cistron is inwards enabled solid pose down or not?

Syntax:
boolean variableName = driverObject.findelement(By.locator("value").isEnabled();

Example:
boolean a = driver.findElement(By.id("next")).isEnabled();
System.out.println(a); //true
----------------------------------------
16) isDisplayed()
It checks if the chemical cistron is displayed or not?

Syntax:
boolean variableName = driverObject.findelement(By.locator("value").isDisplayed();

Example:
boolean a = driver.findElement(By.id("next")).isDisplayed();
System.out.println(a); //true
-----------------------------------
17) manage().window().maximize()
Syntax:
driver.manage().window().maximize();

Example:
driver.get("https://gmail.com/");
driver.manage().window().maximize();
-------------------------------------------------
18) isSelected()
It checks if the depository fiscal establishment lucifer box or Radio push is selected or not?

Syntax:
boolean variableName = driverObject.findelement(By.locator("value").isDisplayed();
-----------------------------------------------------

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post