logo image

WebDriver methods in selenium

Once driver object is created, we can perform below methods on a driver.

  1. get(url) : It loads new webpage in the current window. Example :

more information :


  1. navigate() : It allows the driver to access the browsers history. This method returns "WebDriver.Navigation" interface. Interface has the following methods:
    • back(): Moves back in the history.
    • forward() : Moves forward in the history.
    • refresh(): Refresh the current page
    • to(url) : Loads a new webpage in the current browser window. more information :


  1. quit() : It closes every associated sites Example:
  1. close() : It closes current site,which is open by webdriver class. Example :
  1. switchTo() : This method helps handling web pop up's, working with frames, go to active element and back to main page or frame. Example :
driver.switchTo().alert().accept(); // accepts the popup
driver.switchTo().alert().dismiss(); // dismiss the popup
driver.switchTo().alert().sendkeys(); // Enter the value and accept the popup
  1. getCurrentUrl() : It gets the current url and represents a string. Example :
  1. getPageSource() : It gets source of the page Example :
  1. getTitle() : Its gets the title of the current page and verifies the page title Example :
WebDriver driver = new ChromeDriver();
driver.findElement(By.name("q")).sendKeys("Today's weather");
System.out.println(driver.getTitle());// returns the current page title and prints in the console 
  1. manage() : It returns "WebDriver.Options" interface. Interface has the below methods
    • deleteAllcookies();
    • getCookies()
    • timeouts()
    • window() Example:
 WebDriver driver = new ChromeDriver();
 driver.manage().window().maximize(); // maximizes the current page
  1. findElements(By by) : It finds all elements within the current page using the given mechanism. Example :
 List <WebElement> inputs= driver.findElements(By.xpath("//"));
  1. findElements(By by) : It finds first WebElement using the given mechanism. Example :
WebElement search = driver.findElement(By.xpath("//"));