Thursday, 14 January 2016

Print Gmail chat list name using slenium

package All_Types_Run;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class Gmail_Chat_List_Names {
  
WebDriver driver;

@BeforeMethod
public void openurl()throws InterruptedException
{
   // Scanner in = new Scanner(System.in);
  //  System.out.println("Enter the gmail id: ");
  //  String emailId = in.next();
  //  System.out.println("Enter the pass: ");
 //   String pass = in.next();
  
    driver = new FirefoxDriver(); //open firefox browser
  
    //login to gmail
    driver.get("http://www.gmail.com");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(40,TimeUnit.SECONDS);
    driver.findElement(By.name("Email")).sendKeys("@gmail.com");
    driver.findElement(By.name("Passwd")).sendKeys("99");
    driver.findElement(By.name("signIn")).click();
}
@Test
public void chatlist() throws InterruptedException
{
    List<WebElement> chatboxsize = driver.findElements(By.xpath("//table[@class='vH']/tbody"));
    System.out.println("number of people in the gmail chat: "+chatboxsize.size());
    String name="";
    for (int i=1; i <=chatboxsize.size(); i++)
    {
        name = driver.findElement(By.xpath("//table[@class='vH']/tbody["+i+"]/tr[1]//span[1]")).getAttribute("textContent");
        System.out.println(name);
   }
}
@AfterMethod
public void closeBrowser(){
    driver.close();
}
}

No comments:

Post a Comment