Unable to locate objects in gmail | Selenium Forum
M
Posted on 26/01/2016
Sir, have used frames & tried to locate a email object in gmail.Did not work as expected.
Query- will this work with xpaths or should i use javascriptexecutor?
Following is my code:
===================

package p1;

import java.util.ArrayList;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Gmail_login_cc {

public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver w=new FirefoxDriver();
w.get("http://www.gmail.com/");
w.findElement(By.xpath("//*[@id='Email']")).sendKeys("chaitra108@gmail.com");
w.findElement(By.xpath("//*[@id='next']")).click();
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys("XXXXXXXXX");//put ur pwd
w.findElement(By.xpath("//*[@id='Passwd']")).sendKeys(Keys.ENTER);
List <WebElement>L=new ArrayList<WebElement>();
List <WebElement>L2=new ArrayList<WebElement>();
//L=w.findElements(By.xpath("//div[contains(@text(), 'unread,')]"));
//L=w.findElements(By.partialLinkText("unread"));
//System.out.println(L.get(0).getText());
//-----------------------------

//WebElement mailLink = w.findElement(By.xpath("//*[@id=':lp']"));
//L = w.findElements(By.name("Timesjobs Job Alert"));
//L = w.findElements(By.tagName("email"));
//L = w.findElements(By.xpath("//div [@class='y6']/span[contains(.,'<How to >')]"));

L=w.findElements(By.tagName("iframe"));
for(int i=0;i<L.size();i++)
{try{
w.switchTo().frame(i);
L2=w.findElements(By.xpath("//*[@class='y6']/span"));
//L2=w.findElements(By.xpath("//div[@class = 'y6']/span[contains(., 'XLRI brings')]"));
//L2=w.findElements(By.xpath("//div[@class = 'y6']/span[contains(., 'XLRI brings')]"));
WebElement mailLink = w.findElement(By.xpath("//*[@id=':lp']"));
mailLink.click();
System.out.println("mailLink"+mailLink.size());
System.out.println("l2 size"+L2.size());
System.out.println("frame"+i);
w.switchTo().defaultContent();
}
catch(Exception e)
{
System.out.println(e.getStackTrace());
System.out.println("i"+i);
}

}

System.out.println(L.size());

}

}