Selenium Basic Classes

Selenium WebDriver provides several classes and interfaces that are useful for automating web application testing. Here are some of the key classes and interfaces:

Key Interfaces/Classes in Selenium

  • WebDriver Interface:

    The main interface for testing web applications. It provides methods for interacting with web pages, such as opening a URL, navigating, managing browser windows.
    Like if we want to run our test scripts in different browsers, we have to create objects of those browsers and we can do that by using the below code:
    WebDriver driver = new ChromeDriver();
    WebDriver driver = new FirefoxDriver();
    Learn more
  • By Class:

    Provides various methods for locating elements on a web page, such as by ID, name, class name, tag name, link text, partial link text, CSS selector, and XPath.
    Like if we want to locate an element by using the ID, we have to use the By class and itd methods like:
    By.id("elementId");
    Learn more
  • WebElement Interface:

    Represents an HTML element on a web page. It provides methods for interacting with elements, such as clicking, sending keys, and retrieving text and attributes.
    Like if we want to click on a button, we have to create an object of the WebElement interface and use its interaction methods like:
    WebElement element = driver.findElement(By.id("elementId"));
    element.click();
    Learn more
  • Actions Class:

    Provides methods for handling complex user interactions like keyboard and mouse events including keyDown, keyUp, click, doubleClick, contextClick, drag and drop, moveToElement, etc.
    Like if we want to perform a drag and drop operation, we have to create an object of the Actions class and use its methods like:
    Actions actions = new Actions(driver);
    actions.dragAndDrop(sourceElement, targetElement).build().perform();
    Learn more

Why do we need to learn these classes?

These classes and interfaces are the core components of Selenium WebDriver. If we will remember these classes and their methods, we will be able to write effective and efficient test scripts for automated testing.

Let's learn WebDriver Interface and its methods in the next tutorial.