Please DONOT use GMail for your automation purposes [its javascript is heavily complex and its not worth the effort in trying to automate it, unless and until you are working for Google]
If you merely would like to fetch emails from a gmail account and assert its content, you should be using Java APIs for doing it and NOT WebDriver/Selenium.
It should help you get started.
Thanks & Regards
Krishnan Mahadevan
"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @
http://wakened-cognition.blogspot.com/
On Thu, Feb 14, 2013 at 2:15 PM, Selenium Rao
<seleni...@gmail.com> wrote:
Hello Friends,
My requirement is
Log in to http://gmail.com with valid credentials, Open the first email and assert the content and logout.
Here is the code but I am not able to click on the first email, can you please let me know, where to correct it.
public static void main(String[] args) {
///Comment1:Captured all the xpath's as a string and calling in the xpaths below
String login = "//*[@id='Email']";
String passwd = "//*[@id='Passwd']";
String submit = "//*[@id='signIn']";
String more = "//*[@id=':pb']";
String firstitem ="//*[@id=':p1']" ;
String Myname = "//*[@id='gbi4t']";
String logout ="//*[@id='gb_71']";
String mailInboximg="//*[@id=':2z']/table/tbody/tr[2]/td[2]/div";
WebDriver d = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(d,10);
d.get("http://mail.google.com");
d.findElement(By.xpath(login)).sendKeys("myuserid");
d.findElement(By.xpath(passwd)).sendKeys("******");
d.findElement(By.xpath(submit)).click();
Comment2: Here I am calling a wait, till the page is loaded checking one of the element called "more" button.
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(more)));
// Capturing it in the list
List<WebElement> allLinks =d.findElements(By.xpath("//*[@id=':rr']/div/div"));
System.out.println(allLinks.size());
//System.out.println(allLinks.
for (int i =0; i<allLinks.size(); i++){
System.out.println(allLinks.get(i).getText());
}
allLinks.get(1).click();
}
}
Results
1.In the below code all the mails are getting read and displayed in the console
2. But getting below exception.
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at test.googlemail.main(googlemail.java:46)
My requirement is check the content also please can any one of you let me know where I need to correct it.
Thanks and Regards,
Sachin (Selenium22013)
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/3C16j_MX5_UJ.
For more options, visit https://groups.google.com/groups/opt_out.