top of page

Selenium Java Tutorial

GMail Automation Example

Write A Simple Automation Script For GMail Sign In.

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 : Step-1 Launch gmail website in browser and find 'SIGN IN' button, click on this button by selenium web driver.

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

Step-3 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; import; 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"); driver.get(baseurl); // click on Sign In button WebElement signIn =driver.findElement(By.xpath("//a[text()='Sign In']"));; Thread.sleep(1000); // Enter UserName Value and click On Next Button WebElement userName =driver.findElement(By.xpath("//input[@type='email']")); userName.clear(); userName.sendKeys("Your Gmail User Name/Phone Number"); WebElement nextButton =driver.findElement(By.xpath("//span[text()='Next']"));; Thread.sleep(1000); // Enter Password Value and click On Next Button WebElement userPassword =driver.findElement(By.xpath("//input[@type='password']")); userPassword.clear(); userPassword.sendKeys(" Your Gmail Password"); Thread.sleep(1000); WebElement nextButton1 =driver.findElement(By.xpath("//span[text()='Next']"));; Thread.sleep(8000); System.out.println("Waiting for 8 sec"); driver.close(); System.out.println("closed chorme browser"); // LogOut From Gmail WebElement userProfile = driver.findElement(By.xpath("//a[contains(@href,'SignOutOptions') and @role='button']"));; Thread.sleep(3000); System.out.println("User clicked profile button"); WebElement signout = driver.findElement(By.xpath("//a[contains(@href,'Logout') and text()='Sign out']"));; System.out.println("User clicked signout button"); driver.close(); System.out.println("closed chorme browser"); } }

Refer next page Handling Drop-Downs
bottom of page