Tuesday, June 14, 2016

Selenium WebDriver: get() vs. navigate().to()?

Question "What is difference between Selenium WebDriver get() and navigate().to() methods" is asked often on QA Automation interview. Answer is  there are the same methods performed HTTP GET request, but Navigation object has more ability to navigate like browser backward(), forward(), etc.

But navigate() method returns browser history in the form of Navigation object.
---------------
javadoc for WebDriver https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebDriver.html#get-java.lang.String-


WebDriver.get

void get(java.lang.String url)
Load a new web page in the current browser window. This is done using an HTTP GET 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. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change whilst your test is executing the results of future calls against this interface will be against the freshly loaded page. Synonym for WebDriver.Navigation.to(String).
Parameters:
url - The URL to load. It is best to use a fully qualified URL

navigate

WebDriver.Navigation navigate()
An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
Returns:
A WebDriver.Navigation that allows the selection of what to do next

WebDriver.Navigation.to

void to(java.lang.String url)
Load a new web page in the current browser window. This is done using an HTTP GET 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. Should a meta-redirect "rest" for any duration of time, it is best to wait until this timeout is over, since should the underlying page change whilst your test is executing the results of future calls against this interface will be against the freshly loaded page.
Parameters:
url - The URL to load. It is best to use a fully qualified URL

navigate

WebDriver.Navigation navigate()
An abstraction allowing the driver to access the browser's history and to navigate to a given URL.
Returns:
A WebDriver.Navigation that allows the selection of what to do next


WebDriver.Navigation methods
 

Method Summary

All MethodsInstance MethodsAbstract Methods
Modifier and TypeMethod and Description
voidback()
Move back a single "item" in the browser's history.
voidforward()
Move a single "item" forward in the browser's history.
voidrefresh()
Refresh the current page
voidto(java.lang.String url)
Load a new web page in the current browser window.
voidto(java.net.URL url)
Overloaded ve



No comments:

Post a Comment