Difference between webdriver.get() and webdriver.navigate()

前端 未结 14 1459
悲哀的现实
悲哀的现实 2020-11-28 04:27

What is the difference between get() and navigate() methods? Does any of this or maybe another method waits for page content to load? What do I rea

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 04:40

    There are some differences between webdriver.get() and webdriver.navigate() method.


    get()

    As per the API Docs get() method in the WebDriver interface extends the SearchContext and is defined as:

    /**
     * Load a new web page in the current browser window. This is done using an HTTP POST operation,
     * and the method will block until the load is complete.
     * This will follow redirects issued either by the server or as a meta-redirect from within the
     * returned HTML.
     * Synonym for {@link org.openqa.selenium.WebDriver.Navigation#to(String)}.
     */
    void get(String url);
        
    
    • Usage:

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

    navigate()

    On the other hand, navigate() is the abstraction which allows the WebDriver instance i.e. the driver to access the browser's history as well as to navigate to a given URL. The methods along with the usage are as follows:

    • to(java.lang.String url): Load a new web page in the current browser window.

      driver.navigate().to("https://www.google.com/");
      
    • to(java.net.URL url): Overloaded version of to(String) that makes it easy to pass in a URL.

    • refresh(): Refresh the current page.

      driver.navigate().refresh();
      
    • back(): Move back a single "item" in the browser's history.

      driver.navigate().back();
      
    • forward(): Move a single "item" forward in the browser's history.

      driver.navigate().forward();
      

提交回复
热议问题