Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App

Related Articles

Selenium Program to Login to a Specific Web Page

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Selenium RC (Selenium Remote Control) is one of the Selenium Components which was developed by Paul Hammant. It is an automation testing tool for web applications. To create test scripts, testers are allowed to use many programmings languages such as Java, Python, Ruby, C#, JavaScript, Perl, and PHP. Here we are using Java for writing test scripts.

Tip: One should be well versed with Eclipse and JDK understanding concepts.


  • Create New Project, Click on File
  • Create a new java class
  • Download the latest Chrome Driver and Selenium Web Driver for Java
  • Click on Classpath and Select Add External JARs.

These above steps are as depicted below with help of visual aids for better understanding. 

Step 1: To Create New Project, Click on File –> New –> Java Project.

After creating a new project, give the project name “Login_Test” and click on Finish. 

Step 2: Create a new java class 

For creating a new Java class, Right-click on “Test”, Click on new and select Class. Given the class name “Login_test” and click Finish.

Now we have to import Selenium Web Driver and Chrome Driver.

Step 3: Download the latest Chrome Driver and Selenium Web Driver for Java. After downloading, unzip the downloaded files. Right-click on “Testing”, Click on Build Path, and Select Configure Build Path.

Step 4: Click on Classpath

4.1: Initially alongside select Add External JARs.

4.2: Now go to the Selenium driver downloaded file, select both these jar files and click on ‘Open’.

4.3: Go to the same folder, open the “libs” folder, select all the jar files, and click on ‘Open’.

After adding all these required Jar files, below is the given code to test the login page.



// Java Program to Login to a specific Webpage
// Using Selenium WebDriver and ChromeDriver
// Importing package module to code fragment
package login_test;
// Importing required classes
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
// Main class
public class Test {
    // Main driver method
    public static void main(String[] args)
        // Path of chrome driver
        // that will be local directory path passed
        WebDriver driver = new ChromeDriver();
        // URL of the login website that is tested
        // Maximize window size of browser
        // Enter your login email id
        // Enter your login password

After adding this code, click on the ‘Run’ button.

Chrome Driver will start successfully and Chrome browser will open. It will automatically open the GeeksforGeeks login page and add details for login. If the details are valid, it will redirect to its website.

My Personal Notes arrow_drop_up
Last Updated : 30 Jan, 2022
Like Article
Save Article
Similar Reads