Monday, June 16, 2014

Print the name of the people in the gmail chatbox list and number of people in the gmail chat box in lefthand side. Realtime scenario.

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.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class GmailChatBox {
  
WebDriver driver;

@BeforeTest
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(emailId);
    driver.findElement(By.name("Passwd")).sendKeys(pass);
    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);
    }
}
@AfterTest
public void closeBrowser(){
    driver.close();
}
}

4 comments:

  1. Hi Sanjay,
    Can just tell me whr this cls is available in //table[@class='vH']/tbody" .

    ReplyDelete
  2. Please open firepath, and there verify this xpath-
    //table[@class='vH']/tbody
    you will get this.

    ReplyDelete
  3. Hi Sanjay, Thanks for reply but is it hidden table or wt?

    ReplyDelete
  4. No its not hidden. Please expend the html code in Firebug and there you will get this.

    ReplyDelete