Continuous Test Orchestration And Execution Platform Online

Perform automated and live-interactive testing on 3000+ real desktop and mobile devices online.

How do I write and run test scripts in Selenium?

You can write and execute Selenium scripts with different programming languages and frameworks. However, for demonstration, we will take an example of Java programming. Besides, you must ensure the following things are configured on your machine.

  • Java development environment
  • IDE (Integrated Development Environment)
  • Drivers and Grids to run the test in different environments. (if you are running tests on cloud, you can skip this step)

Following are the steps to write and run test scripts in Selenium Java.

  • Create a Java Project
  • Download Maven, add the MAVEN HOME system variable, and update it with the maven installed folder location.
  • In the pom.xml file, add all the dependencies needed to create and run the Selenium script.
  • Add the following Selenium dependencies to create your tests.


    Test Scenario: The script launches the LambdaTest login page (, enters a valid name and password, clicks on the Login button and verifies the page’s title to ensure the user logged in successfully and then routed to the LambdaTest home page.

    Shown below is the test script for the above test scenario.

    Package MyTests;
     import org.openqa.Selenium.By;
     import org.openqa.Selenium.WebDriver;
     import org.openqa.Selenium.WebElement;
     import org.testng.Assert;
     import java.util.concurrent.TimeUnit;
     public class SimpleTest {
         public static void main(String[] args) {
             WebDriver driver = new ChromeDriver();
             String url = "";
             (10, TimeUnit.SECONDS);
             WebElement email = driver.findElement("email"));
             WebElement password = driver.findElement("password"));
             WebElement loginButton = driver.findElement
             String title = "Welcome - LambdaTest";
             String actualTitle = driver.getTitle();
                "Page title doesnt match");
     System.out.println("User logged in successfully");

    To implement the above Login scenario, you need to

    • Identify web elements to enter the email and password and click the Login button. You can use Selenium locators to do this.
    • Right-click on the particular element and click Inspect, which helps identify that specific element’s locator.

  • To begin, specify the driver's path and then instantiate the required browser for that specific driver.
  • To run the tests, right-click on your test class and click Run.
  • Different Type of Selenium

    Once tests are executed, you can see the results in the IDE console.

    Different Type of Selenium

Test your websites, web-apps, or mobile apps seamlessly with LambdaTest.

Start Free Testing

Earn resume-worthy Selenium certifications that help you land a top job.

Learn More

Test your web or mobile apps

Test orchestration and execution cloud of 3000+ browsers and OS


24/7 support


Enterprise grade security


Fastest test execution cloud