WebDriver Methods

We will look in detail for each of the webdriver methods that we have. The first that we use is 'driver.get(url)' after starting the browser.

When we get the driver object, the below are the methods that we can perform operation on a driver. In IDE like eclipse, when we add period (. ) you will show all the below methods.
get()
getCurrentUrl();
getTitle()
findElements()
findElement()
getPageSource()
close()
quit()

Method Name :- get()

Syntax: get(url)
Example: driver.get();
Purpose: 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.
Parameters: URL - The URL to load and it should be a fully qualified URL

Method Name: getCurrentUrl()

Syntax: getCurrentUrl()
Example: driver.getCurrentUrl();
Purpose: Gets a string representing the current URL that the browser is opened.
Returns: The URL of the page currently loaded in the browser

Method Name: getTitle()

Syntax: getTitle()
Example: driver.getTitle();
Purpose: Gets the title of the current web page.
Returns: The title of the current page, with leading and trailing white space stripped, or null if one is not already set

Method Name: findElements()

Syntax: findElements(By by)
Example: driver.findElements(By.xpath("//");
Purpose: Find all elements within the current page using the given mechanism.
Parameters: By - The locating mechanism to use
Returns: A list of all WebElements, or an empty list if nothing matches

Method Name: findElement()

Syntax: WebElement findElement(By by)
Example: driver.findElements(By.xpath("//");
Purpose: Find the first WebElement using the given method.
Parameters: By - The locating mechanism
Returns: The first matching element on the current page
Throws: NoSuchElementException - it will return exception if no matching elements are found

Method Name: getPageSource()

Syntax: getPageSource()
Example: driver.getPageSource();
Purpose: Get the source of the currently loaded page. If the page has been modified after loading (for example, by Javascript) there is no guarantee that the returned text is that of the modified page.
Returns: The source of the current page

Method Name: close()

Syntax: void close()
Example: driver.close();
Purpose: 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.

Method Name: quit()

Syntax: void quit()
Example: driver.quit();
Purpose: Quits this driver instance, closing every associated window which is opened.

Method Name: getWindowHandles()

Syntax: Set getWindowHandles()
Example: driver.getWindowHandles();
Purpose: Return a set of window handles which can be used to iterate over all the open windows of this Webdriver instance by passing them to switchTo().WebDriver.Options.window()
Returns: A set of window handles which can be used to iterate over all the open windows.

Method Name: getWindowHandle()

Syntax: String getWindowHandle()
Example: driver.getWindowHandle();
Parameter: Return an opaque handle to this window that uniquely identifies it within this driver instance. This can be used to switch to this window at a later date
switchTo
WebDriver.TargetLocator switchTo()
The next future commands will be performed to a different frame or window.
Returns: A Target Locator which can be used to switch or select a frame or window

Method Name: navigate()

Syntax: WebDriver.Navigation navigate()
Example: driver.navigate.to("");
Purpose: An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
Returns: A WebDriver.Navigation that allows the selection of what to do next

Click here to know more on Navigation methods

Method Name: manage()

Syntax: WebDriver.Options manage()
Purpose: Gets the Option interface
Returns: An option interface

Selenium Tutorials: 

Comments

Very helpful

i need all driver object method in java

Very helpful notes.Thank you.

Very good information

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.