EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Selenium Commands

By Aanchal SinghAanchal Singh

Home » Software Development » Software Development Tutorials » Selenium Tutorial » Selenium Commands

Selenium Commands

Introduction to Selenium Commands

Selenium commands are specifically used in the Selenium Web driver framework, for testing the application in a web browser. The commands can be categorized as four main groups, that are, Browser commands, WebElement commands, Get commands and Navigation commands. Some of the commonly used commands in Selenium test scripts are sendKeys, click, IsDisplayed, IsSelected, refresh, navigate, back, quit, close, getTitle, getCurrentTitle, getSize, etc. for performing operations, for fetching values, for enabling actions on the web application.

Basic Selenium Commands

Below are few basic commands in selenium.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

  • Get method: This method is a part of the driver class and can be accessed by using driver.get() method. It can be used to navigate to a web page by passing a URL as a parameter.

Get method

  • Navigate method: This method like ‘get’ is a part of same class and the driver.navigate().to() method opens a web page like driver.get() method.

Navigate method

  • Writing in a textbox: The sendKeys() method help in writing in a textbox. It can also act for entering any element of text input type.

Writing in a textbox

  • Refreshing the browser: A browser can be refreshed in multiple ways. These are listed as below:
  1. Using navigate().refresh() command
  2. Using sendKeys(Keys.F5) on any textbox on the webpage
  3. Using get(“URL”) with current URL
  4. Using navigate().to(“URL”) with current URL

Refreshing the browser

  • Close command: This Selenium command helps in killing the window which is currently working and over which the WebDriver has the control. The return type for this command is void.

Close command

  • Get Title command: This method helps in returning the title string of the current page in the browser. The return type for this method is a string. It is advisable to save this object as a string object or variable.

Get Title command

  • Get Current URL command: This method is used when the string containing the URL currently opened in the browser in the window. It is useful for logging purposes.

Get Current URL command

  • Get Page Source command: This method helps in getting the source code of a web page. This returns a string value.

Get Page Source command

  • void forward(): This Selenium command helps in simulating the window to browse to the forward button action of a browser. It is supposed to move forward by a single page into the browser’s history data.

void forward():

  • Click Command: This method is used to perform the click action by the web element. This is one of the most common methods which interact with web elements like checkboxes, buttons, windows, etc.

Click Command

Intermediate Commands

The following commands should be known to you once you are comfortable with the basic Selenium commands.

  • GetWindowHandle Command: This Selenium command helps to get the window handle of the current window.
  • GetWindowHandles Command: This command helps in getting window handles of all current windows that are open in a browser.
  • SwitchTo Window Command: This Web driver command helps in moving between named windows by using the switchTo method. A user can also send a window handle to switchto().window() method where it is also possible to iterate over any open window as well.
  • SwitchTo Frame command: By using this command it is possible to move between named frames by using the SwitchTo method.
  • SwitchTo PopUp Command: Similar to above switchTo commands, this method can also help in switching PopUp windows. Once this action is triggered then a pop up is opened and it can be accessed by an alert and it will return the currently open alert object. With the help of this object, the user can accept, dismiss or read the contents into any prompt.
  • IsDisplayed Command: This method helps in checking whether an element is visible or not. It returns true if the element is present and also visible on the page. It throws the necessary exception if the element is not present.
  • IsEnabled: This method returns either true or false based on the state of the element. It mostly returns true for all items except for those which are intentionally disabled.
  • Submit command: This method helps in the initiation of submission of an HTML form. It does not allow any parameter and if it is leading to the current page then it will wait until the new page is loaded.
  • GetCssValue Command: This method provides the value of the CSS property which belongs to the element.
  • GetLocation Command: This method helps in getting the location of any element on the page. The user can easily get the X and Y coordinates of any specified element.

Advanced Commands

Below are some advanced commands in selenium:

  • Handling iframes by ID or Name

To identify an iframe the user must identify the ID or Name of the frame which is to be used. To do this user must first inspect the web page by using web inspector tools. Once this is done following web driver command can be used to switch between different iframes.

driver.switchTo().frame("frameID");
driver.switchTo().frame("frameName");

  • Exception Handling

There may be cases where programs get interrupted and these interruptions can be said as exceptions. Like other languages, Selenium web driver also supports exception handling. It can catch a single exception or even multiple exceptions.

  • Handling waits and conditions

There are different commands which can handle waits. They can be named as:

 PageLoadTimeOut(time,unit) and implicitlyWait()

Similarly for Conditions below can be used:

isDisplayed(), isEnabled(), isSelected()

Tips and Tricks to use Selenium Commands

  • The best method for creating Web driver Instance

By making use of <Factory> design template user can create object for a particular browser type.

  • Method to check if an element exists

The user can make use of <findElements> to check if an element exists or not.

Popular Course in this category
Selenium Automation Testing Training (9 Courses, 4+ Projects, 4 Quizzes)9 Online Courses | 4 Hands-on Projects | 38+ Hours | Verifiable Certificate of Completion | Lifetime Access | 4 Quizzes with Solutions
4.5 (6,051 ratings)
Course Price

View Course

Related Courses
Penetration Testing Training Program (2 Courses)Software Testing Training (9 Courses, 2 Projects)
  • Avoiding exceptions and checking for an element together

The above tag may lead to <NoSuchElementException>. By making use of wait feature this error can be avoided and it also allows to test the web element.

Conclusion

By making using of Selenium and these commands any web application can be automated easily. Selenium being an open source tool is easily available and hence can be used for testing of all web-based applications. Above commands can briefly help you get through the basics and advanced commands that are used in Selenium.

Recommended Articles

This has been a guide to Selenium Commands. Here we have discussed concept, basic, intermediate as well as advanced Selenium Commands along with tips and tricks to use effectively. You may also look at the following article to learn more –

  1. Selenium Software
  2. Selenium Tools
  3. Selenium Architecture
  4. Components of Selenium

Selenium Automation Testing Training (9 Courses, 4+ Projects)

9 Online Courses

4 Hands-on Projects

38+ Hours

Verifiable Certificate of Completion

Lifetime Access

4 Quizzes with Solutions

Learn More

1 Shares
Share
Tweet
Share
Primary Sidebar
Selenium Tutorial
  • Basics
    • What is Selenium
    • Uses of Selenium
    • Career in Selenium
    • Selenium Software
    • Selenium Architecture
    • Components of Selenium
    • How to Install Selenium
    • Install Selenium IDE
    • Selenium Framework
    • Selenium Commands
    • How to Use Selenium?
    • Selenium Testing
    • Selenium Automation Testing
    • Selenium Load Testing
    • Selenium Grid
    • What is Selenium Web Driver
    • Selenium Webdriver Commands
    • What is XPath in Selenium
    • Assertions in Selenium
    • Selenium Tools
    • Selenium Interview Questions

Related Courses

Selenium Automation Testing Course

Penetration Training Course

Software Testing Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Selenium Automation Testing Training (9 Courses, 4+ Projects) Learn More