Basic Selenium Commands

Get Command

get() command is use to open a new web page in the current browser.

Command: driver.get(“URL”);

Example :

driver.get("http://google.com");

 

Get Title Command

getTitle() command is use to get the title of the current page.

Example :

driver.getTitle();

 

Get Current URL Command

getCurrentUrl() command is use to get the URL of the page currently loaded in the browser.

Example :

driver.getCurrentUrl()

 

Close Command

close() command is use to close the current window of the browser, if it’s the last window it will close the browser.

Example :

driver.close();

 

Quit Command

quit() command is use to quit the browser and all the opened windows in the browser.

Example :

driver.quit();

 

Get Page Source Command

Purpose: This command is use to get the source of the last loaded page.

Example :

driver.getPageSource();

 

To Command

to() command is use to navigate on specific page or URL in between the  test Command :

Parameters : url – The URL to load. It is best to use a fully qualified URL

driver.navigate().to("https://google.com/");

 

Forward Command

forward() command is use to go on to next page like browser’s forward button.

driver.navigate().forward();

 

Back Command

back() command is use to go back to previous page like browser’s back button.

driver.navigate().back();

 

Refresh Command

refresh() command is use to refresh the current page.

driver.navigate().refresh();

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *