top of page

Gmail Automation Example 

Here is the example of gmail Automation , you will learn how to automate gmail account. Creating a java selenium script to login into gmail account


Here are some steps , please follow



Launch gmail website in browser and find 'SIGN IN' button , click on this button by selenium web driver.


Here we will provide email/phone and click on NEXT button.


Now we will provide Password and click on NEXT button 

Finally Logged into Gmail Account

Here is final code =>

package com.alok.seleniumTutorials;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;


public class LoginIntoGmail {


public static void main(String[] args) throws InterruptedException {

        // ChromeDriver path 

        System.setProperty("", "drivers/chromedriver.exe");


       WebDriver driver = new ChromeDriver();

        String baseurl = "";


        System.out.println("Opening 'Gmail' on chrome browser");


       // click on Sign In button 
       WebElement signIn =driver.findElement(By.xpath("//a[text()='Sign In']"));;


        // Enter UserName Value and click On Next Button

        WebElement userName =driver.findElement(By.xpath("//input[@type='email']"));
 userName.sendKeys("Your Gmail User Name/Phone Number");

       WebElement nextButton =driver.findElement(By.xpath("//span[text()='Next']"));;


      // Enter Password Value and click On Next Button
       WebElement userPassword =driver.findElement(By.xpath("//input[@type='password']"));
 userPassword.sendKeys(" Your Gmail Password");
nextButton1 =driver.findElement(By.xpath("//span[text()='Next']"));;    

Waiting for 8 sec");

        System.out.println("closed chorme browser");


// LogOut From Gmail
       WebElement userProfile = driver.findElement(By.xpath("//a[contains(@href,'SignOutOptions') and @role='button']"));;
User clicked profile button");
signout = driver.findElement(By.xpath("//a[contains(@href,'Logout') and text()='Sign out']"));;
User clicked signout button");
closed chorme browser");



Refer next page Handling Drop-Downs

bottom of page