WebDriver commands – Part 1 (Browser Commands)

In this blogpost, we are going to explore the set of commands used to interact with the web browser. And ideally, this set of commands serve as prerequisite commands for any of the automation script to get scripted.

get command :

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

Syntax :  void get(String url);

Return type : void (returns nothing)

Parameters : Takes the URL as a string

Example :

driver .get(“http://www.google.com“);

OR

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

driver.get(url);


getCurrentUrl command : 

Usage : Used to get the URL of the currently opened web page in the browser.

Syntax : String getCurrentUrl();

Return type : String (Returns the URL of current web page)

Parameters : Nothing

Example :

String currentURL  = driver.getCurrentUrl();

System.out.println(currentURL );

OR

System.out.println(driver.getCurrentUrl());


getTitle command :

Usage : Used to get the title of currently opened web page.

Syntax : String getTitle();

Return type : String (Returns the title of current web page)

Parameters : Nothing

Example :

String title = driver.getTitle();

System.out.println(title);

OR

System.out.println(driver.getTitle());


getPageSource command :

Usage : Used to get the Page source of currently opened web page.

Syntax : String getPageSource();

Return type : String (Returns the Page source of current web page)

Parameters : Nothing

Example :

String pageSource = driver.getPageSource();

System.out.println(pageSource);

OR

System.out.println(driver.getPageSource());


close command :

Usage : Used to close the current tab of browser.

Syntax : void close();

Return type : void (returns nothing)

Parameters : Nothing

Example :

driver.close();


quit command :

Usage : Used to close all the opened tabs of browser

Syntax : void quit();

Return type : void (returns nothing)

Parameters : Nothing

Example :

driver.quit();

That’s all for Browser commands.

Visit Navigation Commands for getting deep understanding of Navigation commands.

Hope it helps you!!

Cheers 🙂

Advertisements

#browser-commands, #close, #get, #getcurrenturl, #getpagesource, #gettitle, #quit, #webdriver-commands