In this article, we will look into some of
the navigation commands in the selenium webdriver.
But Before that,
What is Navigation command and
why use them?
To use these navigation commands we use the
Navigate interface. It has methods to move back, forward as well as to refresh
a web page.
Now let’s look into all this command in
more details
Forward Command:
navigate().forward()
This command lets the user navigate to the
next web page with reference to the browser’s history.
Command –
driver.navigate().forward();
Back Command: navigate().back()
The above command requires no parameters
and takes back the user to the previous webpage in the web browser’s
history.
Command –
driver.navigate().back();
Refresh Command:
navigate().refresh()
This command lets the user refresh the
current web page thereby reloading all the web elements.
Command –
driver.navigate().refresh();
Navigate to Command:
navigate().to(URL)
This command lets the user launch a new web
browser window and navigate to the specified URL.
Sample code:
driver.navigate().to(“https://google.com”);
To understand this practically
Let's do one sample exercise
1)
Navigate to Google Home page
2)
Enter selenium in the search box and enter
3)
Refresh the next page
4)
Come back again to the Google Home page.
Below is the code snapshot for this exercise :