Skip to main content

WebDriver Methods list

Methods in (Java) Selenium Webdriver

Method is a group of statements which is created to perform some actions or operation when your java code call it from main method. Code written Inside methods can not be executed by it self. To execute that method code block, You will need to call that method inside main method block.

You can give any name to your method. Always use method name relative to its functional work.

WEBDRIVER METHODS. Web operations on web Elements
1. get (). 1.click().
2. getCurrentUrl(). 2.sendkeys().
3. getTitle(). 3.clear().
4. getPageSource(). 4.getText().
5. findElement(). 5.getTagName().
6. findElements(). 6.getLocation().
7. close(). 7.isSelected().
8. quit(). 8.isDisplayed().
9. getWindowHandle(). 9.isEnabled().
10. getWindowHandles(). 10.getAttribute().
11. switchTo().
12. navigate().
13. manage().

1. get ().
It is used to open specified url browser in windows.
Syntax:
//to launch the browser
driver. get(http://google.com);
2. getCurrentUrl().
Its Returns title of the Browser
Syntax:
//to launch the browser
Driver.get(http://google.com);
String url=driver.getCurrentUrl();
System.out.println(url);
3. getTitle().
It is used to get the title of current web page
Syntax:
//to launch the browser
driver.get(“http://www.google.com”);
String title=driver.getTitle();
4. getPageSource().
It is used to get the source of current load page
Syntax:
//to launch the browser
driver.get(“http://www.google.com”);
String pagesource=driver.getPageSource();
System.out.println(pagesource);
5. findElement().
It is used to find the first WebElement using the given method.
Syntax:
//to launch the browser
driver.get(“http://www.gmail.com”);
WebElement gmaillink=driver.findElement(By.id());
System.out.println(gmaillink.getText());
6. findElements().
It is used to find all elements within the current page
Syntax:
//to launch the browser
driver.get(“http://www.facebook.com”);
//to findelements
List links=driver.findElements(By.TagName(“a”));
//Counting no of links in result page
System.out.println(links.size());
7. close().
Close the current window, if there are multiple windows, it will close the current window which is active and quits the browser if it’s the last window opened currently.
Syntax:
driver.get(“http://www.etestinghub.com”);
driver.close();
8. quit().
It is used to close every associated window which is opened.
Syntax:
driver.get(“http://www.etestinghub.com”);
driver.quit();
9. getWindowHandle().
Whenever the web driver launches the browser it assigns the unique id to that browser which is called as window handler. This can be captured through the method.
Syntax: driver.getWindowhandle().
10. getWindowHandles().
Whenever multiple windows are opened by webdriver and we want to capture all their ids. We use this method.
Syntax: getWindowHandles().
11. switchTo().
Used to switch from one window to another window (or) window to a frame (or) frame to a window (or) window to an alert
Syntax:
driver.switchTo().window();
driver.switchTo().frame();
driver.switchTo().alert();
12. navigate().
The driver to access the browser’s history and to navigate to a given URL&Refresh page.
Syntax:
driver.get(“http://gmail.com”);
//navigate to page
driver.navigate().to(“http://estestinghub.com “);
//navigate to back
driver.navigate().back();
//navigate to forward
driver.navigate().forward();
//navigate to refresh page
driver.navigate().refresh();
13. manage().
This is used to perform maximize the size of the window.
driver.get(“http://gmail.com”);
driver.manage().window().maximize();

Web operations on web Elements

1.click()

This is used to click on webelements like link, button, radio group, checkbox, images…etc.

2.sendKeys()

Purpose: This is used to sending inputs into text fields and text areas, and also used to select value from the drop down box.

3.clear()

Purpose: This is used to clear the input from existing data.

4.getText()

Purpose: This is used to capture text of the webElement.

5. getTagName()

Purpose: This is used to capture html tag of the webElement.

6.getLocation()

This is used to capture X and Y co-ordinates of webelement in the application.

7.isSelected()

This is used to check, is the check-box is currently checked or unchecked to checked Radio buttons are selected or not.

8. isDisplayed()

This is a Boolean condition. It is used to either an element is visible or not.

If an element is displayed it gives true and an element is not displayed it gives false.

9. IsEnabled()

This is a Boolean condition. It is used to either an element is enable or not.

If an element is enable it gives true and an element is disable it gives false.

10.getAttribute ()

This is used to capture the attributes which are present in web applications.