Showing posts with label Selenium Commands Best Tutorials. Show all posts
Showing posts with label Selenium Commands Best Tutorials. Show all posts

Saturday, April 18, 2020

Selenium WebDriver - Navigation Commands

WebDriver provides some basic Browser Navigation Commands that allows the browser to move backwards or forwards in the browser's history.

Managing history of web based application sometime very useful to complete the test case and functionalities.

List of all Navigation Commands in Selenium WebDriver



1> Navigate To Command: This method loads a new web page in the existing browser window. It accepts String as parameter and returns void.

Syntax: to(String arg0) : void  

Example: driver.navigate().to("https://sltlearning.blogspot.com/");




2> Forward Command: This method enables the web browser to click on the forward button in the existing browser window. It neither accepts anything nor returns anything.

Syntax: forword() : void  

Example: driver.navigate().forward();  

3> Back Command: This method enables the web browser to click on the back button in the existing browser window. It neither accepts anything nor returns anything.

Syntax: back() : void   

Example: driver.navigate().back();  

4> Refresh Command: This method refresh/reloads the current web page in the existing browser window. It neither accepts anything nor returns anything.

Syntax: refresh() : void 

Example: driver.navigate().refresh();  

😀 TIME TO IMPLEMENT the Same IN YOUR ECLIPSE NOW 😀



~~~~~ Time to do Practical Now ~~~~~



  1. Invoke Chrome Browser
  2. Navigate to URL: https://sltlearning.blogspot.com/
  3. Click on the "About SLT Learning" link 
  4. Come back to the Home page using the back command
  5. Again go back to the About SLT Learning Page using forward command
  6. Again come back to the Home page using To command
  7. Refresh the Browser using Refresh command
  8. Close the Browser  

Do not Copy, Write Down in Your eClipse for Better Learning  😀





Selenium WebDriver - Browser Commands

In this post we will learn about all basic commands of WebDriver which help us to automate basic browser actions like opening browser, performing few task and closing the browser.

Below are the list of most commonly used Browser Commands for Selenium WebDriver:

1> Get Command: Get loads a new web page in the existing browser window. It accepts String as parameter and returns void.

Syntax: get(String arg0) : void  

Example:

String base_URL = "https://sltlearning.blogspot.com/";
driver.get("base_URL");




2> Get Title Command: GetTitle method fetches the title of the current web page. It accepts no parameter and returns a String

Syntax: getTitle(): String  

Example: String page_Title = driver.getTitle();



Note: Very useful for assertion to check if we are valid page or not.

3> Get Current URL Command: GetCurrentURL fetches the string representing the Current URL of the current web page. It accepts nothing as parameter and returns a String value.

Syntax: getCurrentUrl(): String  

Example: String current_URL = driver.getCurrentUrl();


Note: Very useful for assertion to check if we are valid url or not.

4> Get Page Source Command: GetPageSource returns the source code of the current web page loaded on the current browser. It accepts nothing as parameter and returns a String value.

Syntax: getPageSource(): String   

Example: String page_Source = driver.getPageSource();



Note: Very useful for assertion to check if we are validating for page content information.


5> Close Command: This method terminates the current browser window operating by WebDriver at the current time. 

If the current window is the only window operating by WebDriver, it terminates the browser as well. 

This method accepts nothing as parameter and returns void.

Syntax: close(): void     

Example: driver.close();  


5> Quit Command: This method terminates all windows operating by WebDriver. 

It terminates all tabs as well as the browser itself. It accepts nothing as parameter and returns void.

Syntax: quit(): void    

Example: driver.quit();  



~~~~~ Time to do Practical Now ~~~~~



  1. Invoke Chrome Browser
  2. Open URL: https://sltlearning.blogspot.com/
  3. Get Page Title name and Title length
  4. Print Page Title and Title length on the Eclipse Console
  5. Get page URL and verify whether it is the desired page or not
  6. Get page Source and Page Source length
  7. Print page Length on Eclipse Console.
  8. Close the Browser


Do not Copy, Write Down in Your eClipse for Better Learning  😀