All IT Courses 50% Off
QA Tutorials

List of Selenium Commands

In Selenium, all those  commands in which we perform certain operations like open a window, or we get a URL or we clear some text from the view are controlled by some commands these commands are called as selenium commands.

There are three types of commands like:

Actions– These commands directly interacts with the page elements like click, type etc.

Accessors– Allows to store the values.

Assertions- It asserts (when this commands fails, test stopped), verifies (when this fails, result logs the failure and continues with execution Wait For (waiting period).

Selenium webdriver has a huge list of commands which are used for test automation which is performed by different operations.

They are:

1.Browser commands

2.Navigation commands

3. Webelements commands

1. BROWSER Commands:

a) Get command

This method opens a new webpage in existing browser. It accepts the parameter as string and returns void.

get(String arg0) : void 

For example the command to load a website will be written as

Driver.get(“www.google.com”)

Create a class browserFunctions in java and package and write the code to open the google webpage.

b) GetPageSource command:

Here the method returns the source code of present webpage loaded on the current browser this accepts no parameter and returns string value.

getPageSource(): String  
driver.getPageSource();  

           or

String PageSource = driver.getPageSource();  

c) GetCurrentURL command:

The job of this command is to fetch the string which represents the current URL of the current webpage. This command returns a string value.

getCurrentUrl(): String  

For example, this command can be written  as

driver.getCurrentUrl();

Or

String CurrentUrl = driver.getCurrentUrl();

d) Get title command:

This command fetches the title of the current webpage. This command accepts no parameter and returns a string.

getTitle(): String

For example this command can be written as

driver.getTitle();    

    OR     

String Title = driver.getTitle(); 

e) Close command

The command is used to terminate the current browser window by operating by the webdriver at the current time. This method returns void.

close(): void 

f) Quit command

This method terminates all the windows operating by the web driver. It closes the browser itself. This returns void.

quit(): void 

For example this can be written as

driver.quit(); 

2. NAVIGATION commands:

  1. Navigate To

This method loads the new page in the current browser window. It returns nothing and accepts a string parameter.

to(String arg0) : void

for example it can be written as

driver.navigate().to(“WWW.H2KINFOSYS.COM”).

b) Navigate Forward

This method does the operation of clicking the forward button of any browser.It will not accept any parameter and not returns any value.

forward() : void 

for example it is written as

driver.navigate().forward();  

c) Navigate Back command

   In this web driver this method simulates the browser’s back button action. It will not allow any parameter and it returns void.

Driver. Navigate ().back ();

For example    driver.navigate ().back();

d) Refresh command

This method works as to refresh the browser. It does not take any parameter and returns void.

driver.navigate().refresh();

For example  driver.navigate().refresh();

3) WEB ELEMENTS COMMANDS:

a) Clear command

This method is used to clear the value of text type element. It will not accept any parameter and returns void.

WebElement user = driver.findElement(By.id(“User”));

user.clear();

b) Sendkeys command

This method prints the characters or values passed in the argument into the associated web element object.it will accept a char sequence as a parameter and its return type is void.

element.sendKeys(“enter text”);

for example:

WebElement user = driver.findElement(By.id("User"));
user.sendKeys(“TechBeamers");

c) Click command

The method does the click action at the web element; it will not accept any parameter and its return type is void.

 element.click();

for example:

WebElement user = driver.findElement(By.id(“User"));
booleanis displayed = user.isDisplayed();

d) GetText command

This method will give you the inner text value of the element and get Text () method may return a blank if the text is hidden.

element.getText();

for example

WebElement link = driver.findElement(By.xpath("MyLink"));
String strlink = link.getText();

Facebook Comments

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Articles

Back to top button
Close
Close

Get Python Course
worth 499$ for FREE!

Offer valid for 1st 20 seats only, Hurry up!!

You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

H2kinfosys Blog will use the information you provide on this form to be in touch with you and to provide updates and marketing.