WebDriver commands – Part 2 (Navigation Commands)

Now, we will have a look at the set of commands defined in Navigation interface and used for different navigations on web page. It is important to understand the internal implementation of all classes and interfaces of WebDriver.

WebDriver is an interface, that contains navigate() method, which returns instance of Navigate interface which is defined in WebDriver interface again.

Have a look at below code snippet to have a clear picture.

// calling navigate() method of WebDriver returns Navigation interface’s reference

Navigation nav = driver.navigate();

// calling one of the method defined in Navigation interface

nav.to(“url”);

OR

// no need to get instance of Navigation interface, instead calling its method directly

driver.navigate().to(“url”);

Navigation1.PNG

And Navigation interface contains the bundle of methods used for navigation purpose in the browser.

Navigation2.PNG

I hope it’s clear.

Now, have a look at Navigation commands one by one.

to command :

Usage : Used to open the URL passed as a parameter in the browser window.

Syntax : void to(String url) OR void to(URL url);

Return type : void (returns nothing)

Parameters : Takes the URL as a string OR URL instance.

Example :

driver.navigate().to(“http://google.com”);

OR

String url = “https://seleniumatfingertips.wordpress.com”;

driver.navigate().to(url);

OR

driver.navigate().to(new URL(“http://google.com”));


back command :

Usage : Simulates the action of clicking Back button of any browser.

Syntax : void back();

Return type : void (returns nothing)

Parameters : Nothing

Example :

driver.navigate().back();


forward command :

Usage : Simulates the action of clicking Forward button of any browser.

Syntax : void forward();

Return type : void (returns nothing)

Parameters : Nothing

Example :

driver.navigate().forward();


refresh command :

Usage : Used to refresh the current web page.

Syntax : void refresh();

Return type : void (returns nothing)

Parameters : Nothing

Example :

driver.navigate().refresh();

Click here to learn about findElement and findElements commands.

Hope it helps you!!
Cheers 🙂

Advertisements

#back, #navigation-commands, #refresh, #to, #webdriver-commands