Top 25 Must to know Selenium Webdriver Commands List

It covers almost all selenium webdriver commands with syntax. This tutorial acts as your guide to all important Selenium Webdriver commands.

1. Browser Commands

Browser commands are the basic commands in Selenium. These commands are the starting point of your selenium script. Browser commands are used to launch browser, maximize it, open url and close browser etc. 

Syntax of all browser commands:

 * Browser Commands       * 

// Set Path of driver executable
String driver_executable_path = "./src/com/techlistic/utils/geckodriver.exe";
System.setProperty("webdriver.gecko.driver", driver_executable_path);

// Launch Browser - Creating a Firefox instance
WebDriver driver = new FirefoxDriver();

// For Chrome
WebDriver driver = new ChromeDriver();

// For Safari
WebDriver driver = new SafariDriver();

// For Opera
WebDriver driver = new OperaDriver();

// For IE
WebDriver driver = new InternetExplorerDriver();

// Open URL 

// Or
String url = "";

// Get Title

// Code implementation
String pageTitle = driver.getTitle();
// Validate Page Title
if(pageTitle == "Techlistic - Home") 
 System.out.println("Test Passed.");
 System.out.println("Test Failed.");

// Get Current URL

//Code implementation
String pageURL = driver.getCurrentUrl();

// Validate Current Page URL
if(pageURL == "") 
 System.out.println("Test Passed.");
 System.out.println("Test Failed.");

// Get Page Source

// Or
String sourceCode = driver.getPageSource();

// Close Current Browser Window

// Close All Browser Windows

// Maximize Browser

// Make Browser Window Full Screen

// Minimize the browser
driver.manage().window().setPosition(new Point(0, -1000));

// Set Size of browser
driver.manage().window().setSize(new Dimension(1920, 1080));

For detailed description refer Browser Commands with Program Example

2. Browser Navigation Commands

These commands are used to move forward and back using browser history.

Syntax for browser navigation commands:

 * Browser Navigation Commands     *

// Navigate Forward

// Navigate Back

// Refresh Page

// Naviagte directly to some URL (which might be external or internal in the website)

3. Find Element Commands

These commands are used to find the gui elements on the web page.

Syntax for all find element commands:

 * Find Element Commands  * 

// Find Single WebElemnt

// Find Multiple WebElements, it returns a list of WebElements

// Find by different locators

// Find web element and store value in WebElement variable for re-usability
WebElement element = driver.findElement(By.xpath("/some/xpath");

For detailed information refer Find Element Commands with Program Example

4. Wait Commands

Wait commands are used to tell Selenium that for how much time it has to wait for an element on a web page before throwing ElementNotFound exception. Or in simple words we can say it is the expected time to load the page or element on the page.

Syntax for Wait Commands:

 *  Wait Commands               *
 *   a. Implicit Wait
 *   b. Explicit Wait
 *   c. Fluent Wait

// Implicit wait - Set wait of 10 seconds
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

// Explicit Wait
WebDriverWait wait = new WebDriverWait(driver, 10); 

// Fluent Wait
Wait wait = new FluentWait(WebDriver reference)
  .withTimeout(timeout, SECONDS)
  .pollingEvery(timeout, SECONDS)

WebElement foo = wait.until(new Function() {
 public WebElement applyy(WebDriver driver) {
  return driver.findElement("foo"));

5. Web Form Commands

These commands are used to perform basic gui actions like., enter text, click and select dropdowns.

Syntax for all web form commands:

 *  Form Commands               *

/* sendKeys()
 *  This command is used for entering value in a Text box
driver.findElement(By.xpath("/some/xpath")).sendKeys("Some Value");

// OR
// Implementation with Webelement
WebElement FIRSTNAME =  driver.findElement(By.xpath("/some/xpath"));
FIRSTNAME.sendKeys("Any Text value");

// Clear Command - to clear the already filled data in text box

/* getText() Command
 *  This command is used to get value/text from a webelement
String textValue = driver.findElement(By.xpath("/some/xpath")).getText();

/* Click Command
 *  click() 

/* Select Class
 *  selectByIndex()
 *  selectByVisibleText()
 *  selectByValue()
WebElement DROP_DOWN = driver.findElement(By.xpath("/select"));

// Create object of Select Class
Select select1 = new Select(DROP_DOWN);

// Option 1

// Option 2

For detailed tutorial refer - Web Form Commands with Program Example

Handle Window Dialog (Upload File)  << Previous      ||      Next >>  Automation Framework Building 1st Step (Code Resuseability)

Refer Selenium Webdriver Tutorials Series

Must Read

Join Telegram channel at
Feel free to ask queries or share your thoughts in comments or email me.


Popular Posts

Top 10 Demo Websites to Practice Selenium Webdriver Online

How To Handle Dynamic Xpaths (Web Table) in Selenium WebDriver

How to Take Screenshot and Partial Screenshot in Selenium WebDriver

Selenium WebDriver - Browser and Navigation Commands

Automation Framework Building 1st step - Implementing Code Re-usablility