First of all Thank you so much for taking time to write lengthy email. I have gone through your email. I understand how to debug/learn the things.
package testing;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class GmailLogin {
private WebDriver driver;
private WebDriverWait wait;
@Before
public void setUp() throws Exception {
System.out.println("Entered the Before Class...!!!!");
driver = new FirefoxDriver();
wait =new WebDriverWait(driver,20);
driver.manage().window().maximize();
}
@Test
public void testGmailLogin()throws Exception{
System.out.println("Entered in to the Main Testing Block");
driver.findElement(By.id("Email")).clear();
driver.findElement(By.id("Passwd")).clear();
driver.findElement(By.id("Passwd")).sendKeys("windows@123");
driver.findElement(By.id("signIn")).click();
System.out.println("Waiting for page to load fully...");
int Checkboxescount = driver.findElements(By.cssSelector("div.T-Jo-auh")).size();
System.out.println("No.of Checkboxes in the mail:"+ --Checkboxescount);
boolean countflag = driver.findElement(By.xpath("//span[@id=':pn']/parent::*/parent::*/parent::*/parent::*/div/div[1]/span/div[1]/span/b[3]")).isDisplayed();
// prints the no.of unread messages if exists in inbox
if(countflag==true){
System.out.print("No.of Unread Messages in Gmail:");
System.out.println(driver.findElement(By.xpath("//span[@id=':pn']/parent::*/parent::*/parent::*/parent::*/div/div[1]/span/div[1]/span/b[3]")).getText());
}else{
System.out.println("No Unread Messages in your INBOX");
}
if(driver.findElement(By.id("gb_71")).isDisplayed())
{
driver.findElement(By.id("gb_71")).click();
}else { System.out.println("sign out button is not displayed to click");}
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id='signIn']")));
boolean Flag = driver.findElement(By.xpath("//input[@id='signIn']")).isDisplayed();
//System.out.println(Flag);
while(Flag)
{
System.out.println("Login form is displayed and browser closed");
driver.quit();
Flag = false;