Selenium WebDriver Methods - Selenium Tutorial, Selenium Methods

After the invention of Selenium, it has undergone many changes and additions to enhance the functionalities and to make it more user friendly. Selenium webdriver is the latest addition to the selenium testing suite and it has made testing using Selenium much easier. Many of its salient features makes the tool highly user-friendly and faster than ever before. Methods in Selenium is one such feature which makes the life of testers easier. Here is an overview on Selenium webdriver methods.

Selenium WebDriver Methods

get()

This is used for loading a new web page in the current window. The method will be blocked till the loading is over.

Syntax: get(url)

Example: driver.get()

get Current Url()

When there is a necessary to get a string of current URL used in the current window, this method will be used.

Syntax: getCurrentUrl()

Example: driver.getCurrentUrl()

getTitle()

This method can be used for getting the title of the current web page

Syntax: getTitle()

Example: driver.getTitle()

findElements()

This can be used to find all the elements using the given mechanism

Syntax: findElements(By by)

Example: driver.findElements(By.xpath(“//”);

findElement()

This method can be used to find the first element in the web page using the given mechanism.

Syntax: WebElement findElement (by by)

Example: webdriver.findElement(By.xpath(“//”);

getPageSource()

When you need to get the source of the current page, this can be used.

Syntax: getPageSource()

Example: driver.getPageSource()

close()

When you need to close only the current window, this method can be used. If multiple windows are open, it will close only the current window.

Syntax: void close()

Example: driver.close()

quit()

When you use this method, all the opened windows will get closed and this can be used for quitting driver instance.

Syntax: void quit()

Example: driver.quit()

getWindowHandles()

This can be used for returning a set of window handles which will be useful for iterating over all the open windows.

Syntax: Set getWindowHandles()

Example: driver.getWindowHandles()

getWindowHandle()

This can be used for switching to a window at a later date.

Syntax: String getWindowHandle()

Example: driver.getWindowHandle()

navigate()

Using this method the history of the browser can be accessed and can navigate to the desired url.

Syntax: WebDriver.Navigation navigate()

Example: driver.navigate.to(“”)

manage()

This can be used to get option interface.

Syntax: WebDriver.Options.manage()

Example: driver.manage()

Leave a Reply

Your email address will not be published. Required fields are marked *