Home >>Selenium Tutorial >Selenium WebDriver Commands

Selenium WebDriver Commands

Selenium WebDriver Commands

As we discussed in the IDE section earlier, Selenium commands are the set of commands used to run our selenium tests.

We have a completely different set of commands in Selenium WebDriver for running various operations. Since we use Java with Selenium WebDriver, commands are simply Java-written methods.

We demand that you go through the Java OOPs (Object-Oriented Programming) concepts in the java programming language before going into the specifics of commands given by Selenium WebDriver. You can also refer to the definition portion of our Java OOPs given in the Java Tutorial.

We have produced our first test script in Selenium WebDriver so far, successfully. Thus one way to display WebDriver 's methods is to open the Eclipse IDE loaded with Selenium Webdriver jar archives, build a WebDriver driver object and click the dot key. It'll give you all of WebDriver 's potential methods.

Method Name

In order to use any function of any type, we need to create a type property, and then all the public methods exist for the category.

Parameter

A parameter is an argument that is passed on to a process to conduct a particular operation.

Return type

Methods will return a value or returning nothing (void). If the void is mentioned after the method, it means, the method is returning no value. If it returns a value, then the value form for e.g. getTitle): (string must be shown.

Now we are going to discuss the various commands WebDriver offers. Selenium WebDriver commands can be generally classified in the following categories.

  1. Browser Commands
  2. Navigation Commands
  3. WebElement Commands

1.Fetching a web page

There are two methods to fetch a web page:

  • Using Get method
    driver.get("www.phptpoint.com")
  • Using Navigate method
    driver.navigate().to("https://phptpoint.com/selenium-tutorial");

2. Locating forms and sending user inputs

driver.findElement(By.id("lst-ib")).sendKeys("phptpoint tutorials");  

3. Clearing User inputs

The clear() method is used to clear the user inputs from the text box.

driver.findElement(By.name("q")).clear();  

4. Fetching data over any web element

Often for some statements and testing we need to retrieve the text written over a web element. We use the method getText() to retrieve data written over some web element.

driver.findElement(By.id("element123")).getText();

5. Performing Click event

driver.findElement(By.id("btnK")).click();  

6. Navigating backward in browser history

driver.navigate().back();  

7. Navigating forward in browser history

driver.navigate().forward();  

8. Refresh/ Reload a web page

driver.navigate().refresh();  

9. Closing Browser

driver.close();  

10. Closing Browser and other all other windows associated with the driver

driver.quit();  

11. Moving between Windows

driver.switchTo().window("windowName");  

13. Moving between Frames

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

14. Drag and Drop

Drag and Drop operation is performed using the Action class.

WebElement element = driver.findElement(By.name("source"));  
WebElement target = driver.findElement(By.name("target"));  
  
(new Actions(driver)).dragAndDrop(element, target).perform();  

No Sidebar ads