Selenium WebDriver Commands
Last Updated :
24 Apr, 2025
Selenium WebDriver is a powerful tool for automating the web browser to perform certain tasks. Selenium supports multiple browsers (such as Chrome, Firefox, Edge, Safari, etc.) and multiple programming languages (such as Java, Python, C#, etc.) so, it is very easy to use and automate tasks on a browser. Selenium WebDriver provides predefined methods and functions that enable developers to interact directly with browsers.
By using WebDriver commands, you can automate various browser tasks such as navigating between browser tabs or windows, clicking on buttons or particular elements on web pages, performing actions on web elements, and other day-to-day tasks.
Let's dive into more details about WebDriver commands in this article, we will learn about the Selenium WebDriver Commands in detail.

What are Selenium WebDriver Commands?
Selenium WebDriver commands are set of functions and method used for controlling or automating the web browser. these command helps developer and tester to write script programmatically using various languages (Java, C#, Python, etc.) to interact with web elements or perform various automation task. These set of command is core of the Selenium WebDriver, so it is very important to know these commands when you are learning about the Selenium.
These Commands are classified into three categories: -
1. Browser commands:
Browser commands provide exact control over the browser's actions, like getting specific pages, extracting information such as page titles and URLs, accessing page source code, and controlling browser windows. Browser commands provide an easy way to interact with web applications and to perform automation and scraping data from web pages.
The Browser Command provides methods: get(), getTitle(), getCurrentUrl(), getPageSource() , close() and quit().
2. Navigation commands:
Navigation commands in Selenium WebDriver perform operations that involve navigating through web pages and controlling browser behaviour. These commands provide an efficient way to manage a browser's history and perform actions like going back and forward between pages and refreshing the current page.
The Navigation Command provides four methods: to(), back(), forward(), and refresh(). These methods allow the WebDriver to perform the following operations:
3. WebElement commands:
To interact with various web element attributes such as (buttons, text fields, links, checkboxes, radio buttons, and more.) selenium webdriver provide a way to interact with all the webelement present on the web page and manipulate them by using Webelement commands. With help of these commands developer or tester can perform various tasks like typing on text field, clicking the button, reading text values, checking and unchecking radio buttons, selecting item from dropdowns etc.
The WebElement Commands provide method: sendKeys(), isDisplayed(), isSelected(), submit(), isEnabled(), getLocation(), clear(), getAttribute(), getText(), getTagName(), click() etc.

Some of the most commonly used commands:
|
1. get(String url) command
| Syntax:
driver.get(URL); It loads a new web page in the current browser window and accepts a string parameter that specifies the URL of the web page to be loaded.
|
2. getTitle() Command
| Syntax:
driver.getTitle(); It gets the title of the current web page displayed in the browser. It does not accept any parameters. It returns the title of the specified URL as a string.
|
3. getCurrentUrl() Command
| Syntax:
driver.getCurrentUrl(); It gets the URL of the current web page shown in the browser. It does not accept any parameters and returns the URL as a string.
|
4. getPageSource() Command
| Syntax:
driver.getPageSource(); It gets the entire page source of the current web page loaded in the browser. It does not accept any parameters, but it does return the page source as a string.
|
5. close() Command
| Syntax:
driver.close(); It closes the current browser window or tab. Also, this command does not accept any types of parameters. It also does not return anything.
|
6. quit() Command
| Syntax:
driver.quit(); It closes all the browser windows and tabs for a particular WebDriver session. This command does not accept any parameters and not return anything.
|
7. to() Command
| Syntax:
driver.navigate().to(URL); Loads a new web page in the current browser window. It accepts a string parameter that specifies the URL of the web page to be loaded.
|
8. back() Command
| Syntax:
driver.navigate().back(); Moves back one step in the browser’s history stack. It does not accept any parameters and does not return anything.
|
9. forward() Command
| Syntax:
driver.navigate().forward(); Moves forward one step in the browser’s history stack. It does not accept any parameters and does not return anything.
|
10. refresh() Command
| Syntax:
driver.navigate().refresh(); Reloads the current web page in the browser window. It does not accept any parameters and does not return anything.
|
11. sendKeys() commands
| Syntax:
// Create WebElement WebElement temp = driver.findElement(By.id("TextBox")); // Perform sendKeys operation temp.sendKeys("GeeksForGeeks"); Entre text automatically into editable field while executing tests. these field are identified using locators like element id, name, class name, etc.
|
12. isDisplayed() command
| Syntax:
WebElement element = driver.findElement(By.id("gfg")); boolean status = element.isDisplayed(); It verifies whether a web element is present and visible on the web page. Returns true if the element is displayed and false if not.
|
13. isSelected() command
| Syntax:
WebElement element = driver.findElement(By.id("software-testing")); boolean status = element.isSelected(); It used on radio, checkboxes, dropdowns to check whether element is selected or not. If the specified element is selected, the value returned is true. If not, the value returned is false.
|
14. submit() command
| Syntax:
WebElement element = driver.findElement(By.id("SubmitButton")); element.submit(); It used to submit forms on browser. It doesn’t require a parameter and returns nothing.
|
15. isEnabled() command
| Syntax:
// Create WebElement WebElement element = driver.findElement(By.id("GFG")); // Perform isEnabled operation element.isEnabled(); Used to checks if an element is enabled for interaction on the web page or not. It returns true if the element is enabled and false if not.
|
16. getLocation() command
| Syntax:
WebElement element = driver.findElement(By.id("Selenium")); Point point = element.getLocation(); //Return System.out.println("X cordinate : " + point.x + "Y cordinate: " + point.y); Retrieves the location of a specific web element on the page in terms of its X and Y coordinates.
|
17. clear( ) command
| Syntax:
WebElement ele = driver.findElement(By.id("edittext")); // Perform clear operation ele.clear(); Used to Clears the content of text entry fields or text areas. It doesn’t require a parameter and returns nothing.
|
18. getSize() command
| Syntax:
WebElement element = driver.findElement(By.id("SubmitButton")); Dimension dimensions = element.getSize(); System.out.println(“Height :” + dimensions.height + ”Width : "+ dimensions.width); Used to retrieves the height and width of a rendered element on the web page.
|
19. getAttribute() command
| Syntax:
WebElement element = driver.findElement(By.id("Submit")); String attValue = element.getAttribute("id"); //This will return "Submit" Used to retrieves the value of a specified attribute of a web element.
|
20. click() command
| Syntax:
// Create WebElement WebElement ele = driver.findElement(By.id("GeeksForGeeks")); // Perform click operation ele.click(); Used to perform click operation on a web element such as a button, link, or checkbox.
|
Selenium WebDriver Commands Example:
Java
// Importing Libraries
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class WebDriverExampleGFG {
public static void main(String[] args) {
// Set the path to the ChromeDriver executable
System.setProperty("webdriver.chrome.driver", "path_to_chromedriver.exe");
// Initialize a new WebDriver instance (in this case, ChromeDriver)
WebDriver driver = new ChromeDriver();
// get(String url) command
driver.get("https://www.example.com");
// getTitle() Command
String pageTitle = driver.getTitle();
System.out.println("Page Title: " + pageTitle);
// getCurrentUrl() Command
String currentUrl = driver.getCurrentUrl();
System.out.println("Current URL: " + currentUrl);
// getPageSource() Command
String pageSource = driver.getPageSource();
System.out.println("Page Source: " + pageSource);
// sendKeys() command
WebElement textBox = driver.findElement(By.id("TextBox"));
textBox.sendKeys("GeeksForGeeks");
// isDisplayed() command
WebElement element = driver.findElement(By.id("gfg"));
boolean isDisplayed = element.isDisplayed();
System.out.println("Element is displayed: " + isDisplayed);
// isSelected() command (for checkboxes, radio buttons, etc.)
WebElement checkbox = driver.findElement(By.id("software-testing"));
boolean isSelected = checkbox.isSelected();
System.out.println("Checkbox is selected: " + isSelected);
// submit() command
WebElement submitButton = driver.findElement(By.id("SubmitButton"));
submitButton.submit();
// isEnabled() command
WebElement isEnabledElement = driver.findElement(By.id("GFG"));
boolean isEnabled = isEnabledElement.isEnabled();
System.out.println("Element is enabled: " + isEnabled);
// getLocation() command
WebElement locationElement = driver.findElement(By.id("Selenium"));
int xCoordinate = locationElement.getLocation().getX();
int yCoordinate = locationElement.getLocation().getY();
System.out.println("X Coordinate: " + xCoordinate);
System.out.println("Y Coordinate: " + yCoordinate);
// clear() command
WebElement clearElement = driver.findElement(By.id("edittext"));
clearElement.clear();
// getSize() command
WebElement sizeElement = driver.findElement(By.id("SubmitButton"));
int elementHeight = sizeElement.getSize().getHeight();
int elementWidth = sizeElement.getSize().getWidth();
System.out.println("Element Height: " + elementHeight);
System.out.println("Element Width: " + elementWidth);
// getAttribute() command
WebElement attributeElement = driver.findElement(By.id("Submit"));
String attributeValue = attributeElement.getAttribute("id");
System.out.println("Attribute Value: " + attributeValue);
// click() command
WebElement clickElement = driver.findElement(By.id("GeeksForGeeks"));
clickElement.click();
// Close the current browser window/tab
driver.close();
// Quit the WebDriver session
driver.quit();
}
}
Similar Reads
Automation Testing - Software Testing
Automated Testing means using special software for tasks that people usually do when checking and testing a software product. Nowadays, many software projects use automation testing from start to end, especially in agile and DevOps methods. This means the engineering team runs tests automatically wi
15+ min read
Automation Testing Roadmap: A Complete Guide to Automation Testing [2025]
Test automation has become a vital aspect of the Software Development Life Cycle (SDLC), aimed at reducing the need for manual effort in routine and repetitive tasks. Although manual testing is crucial for ensuring the quality of a software product, test automation plays a significant role as well.
9 min read
How to Start Automation Testing from Scratch?
Automation Testing is the practice of using automated tools and scripts to execute tests on software applications, reducing manual effort and increasing efficiency. Starting automation testing from scratch involves several key steps, including selecting the right automation tool, identifying test ca
8 min read
Benefits of Automation Testing
In today's fast-paced software development landscape, integrating automation into development and testing processes is crucial for staying competitive. Automation testing offers numerous benefits, including cost savings, faster feedback loops, better resource allocation, higher accuracy, increased t
4 min read
Stages of Automation Testing Life Cycle
In this article, we will explore the phases and methodologies involved in automation testing and the phases of the automation testing lifecycle. We'll cover everything from scoping your test automation to creating a solid test plan and strategy. You'll also learn about setting up the perfect test en
12 min read
Top Automation Testing Books For 2024
In this article, we can explore the top 10 books for automation testing, providing a top-level view of each book's content material and why it's worth considering for everybody interested in this sector. Table of Content Top 10 Books for Automation Testing BooksConclusionFAQs on Top Automation Test
12 min read
Top Test Automation mistakes and Tips for QA teams to avoid them
In the dynamic landscape of software testing, avoiding common test automation pitfalls is crucial for QA teams aiming for efficient and successful testing processes. This article delves into prevalent errors in test automation and provides valuable insights on how QA teams can steer clear of these m
7 min read
Essential Skills for a Successful Automation Tester
In the domain of software testing, automation plays a crucial role in ensuring efficiency, accuracy, and speed. However, to be a successful automation tester, one must possess a specific set of skills beyond just technical proficiency. This article explores the essential skills required for automati
6 min read
Steps to Select the Right Test Automation tools
Selecting the right test automation tools is critical for ensuring efficient and effective testing processes in software development projects. In this article, we will discuss the key steps involved in choosing the most suitable automation tools for your project needs. From understanding project req
5 min read
Best Test Automation Practices in 2024
Test Automation continues to evolve with new technologies and methodologies emerging each year. In 2024, staying updated with the latest best practices is crucial for efficient and effective testing processes. From robust test design to continuous integration and deployment, this article explores th
7 min read