WebDriver methods in selenium

Views: 2   

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 :

  2. navigate() : It allows the driver to access the browsers history. This method returns "WebDriver.Navigation" interface.
    Interface has the following methods:

  3. quit() : It closes every associated sites

  4. close() : It closes current site,which is open by webdriver class.
    Example :

  5. 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
  6. getCurrentUrl() : It gets the current url and represents a
    Example :

  7. getPageSource() : It gets source of the page
    Example :

  8. 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
  9. manage() : It returns "WebDriver.Options" interface. Interface has the below methods

    • deleteAllcookies();
    • getCookies()
    • timeouts()
    • window()
      WebDriver driver = new ChromeDriver();
      driver.manage().window().maximize(); // maximizes the current page
  10. findElements(By by) : It finds all elements within the current page using the given mechanism.
    Example :

    List <WebElement> inputs= driver.findElements(By.xpath("//"));
  11. findElements(By by) : It finds first WebElement using the given mechanism.
    Example :

    WebElement search = driver.findElement(By.xpath("//"));
On By