Login into Gmail Account Using Web Driver
PRACTICAL 7: Login into Gmail Account Using Web Driver
In
the previous post, we had discussed about the installation of Java, and
configuration of Eclipse with selenium WebDriver. Now here, we will be creating
a small Java script in which we will
be doing automated login and logout of Gmail Account.
We
will be following steps: -
1. Importing all the essential libraries.
2. Initialize Chrome Driver
3. Open Gmail using get(
) function
4. Find Placeholder Element using findElement( ) function
5. Send keys to placeholder using sendkeys( ) function
6. Repeat the steps 4&5 for entering password
7. Press Submit Button
CODE:
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.WebElement;
import
org.openqa.selenium.support.ui.ExpectedConditions;
import
org.openqa.selenium.chrome.ChromeDriver;
import
org.openqa.selenium.support.ui.WebDriverWait;
import
java.util.List;
import
org.openqa.selenium.firefox.*;
import
java.util.concurrent.*;
// Create a new instance of the
Firefox driver
WebDriver
driver = new FirefoxDriver();
//
Wait For Page To Load
// Put a Implicit wait, this means
that any search for elements on the page
driver.manage().timeouts().implicitlyWait(10,
TimeUnit.SECONDS);
// Navigate to URL
driver.get("https://mail.google.com/");
// Maximize the window.
driver.manage().window().maximize();
// Enter UserName
driver.findElement(By.id("Email")).sendKeys("
YOUR USER NAME");
// Enter Password
driver.findElement(By.id("Passwd")).sendKeys("YOUR
PASSWORD");
// Wait For Page To Load
driver.manage().timeouts().implicitlyWait(60,
TimeUnit.SECONDS);
// Click on 'Sign In' button
driver.findElement(By.id("signIn")).click();
driver.close();
}
}
Comments
Post a Comment