FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 206   



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 :

    driver.get("http://www.google.com");
    

    more information :
    https://fastfoodcoding.com/tutorials/1509795447169/webdriver-script-that-opens-browser-and-searches-today-s-weather-in-google-com

  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
    Example:

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

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

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

    driver.getPageSource();
    
  8. getTitle() : Its gets the title of the current page and verifies the page title
    Example :

    WebDriver driver = new ChromeDriver();
    driver.get("https://www.google.com/");
    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()
      Example:
      WebDriver driver = new ChromeDriver();
      driver.manage().window().maximize(); // maximizes the current page
      driver.get("https://www.google.com/");
      
  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


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News