Saturday, April 18, 2020

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  😀





No comments:

Post a Comment