Share
Go down
syamp
Posts : 8
Join date : 2012-03-09

How to automated gmail to send email by using Selenium?

on Wed Jul 04, 2012 4:05 pm
Hi Friends,

I am trying to automate the gmail to send an email but couldn't able to click on the "Composer" link, for that have tried with Xpaths, Class names,... but not able.

Can anyone please help me out on this. The below code is used for this.

package test;

import java.util.concurrent.TimeUnit;
import org.junit.*;
import static org.junit.Assert.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;

public class SendEmail {
private WebDriver driver;
private String baseUrl;
private StringBuffer verificationErrors = new StringBuffer();
@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "https://accounts.google.com/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test
public void testGmail() throws Exception {
driver.get(baseUrl + "/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&hl=en");
driver.findElement(By.id("Email")).clear();
driver.findElement(By.id("Email")).sendKeys("abcd");
driver.findElement(By.id("Passwd")).clear();
driver.findElement(By.id("Passwd")).sendKeys("xyz");
driver.findElement(By.id("signIn")).click();
// ERROR: Caught exception [ERROR: Unsupported command [selectFrame]]
driver.findElement(By.xpath("//div[@id=':mq']/div/div")).click();
driver.findElement(By.id(":fz")).clear();
driver.findElement(By.id(":fz")).sendKeys("xyz");
driver.findElement(By.id(":f0")).clear();
driver.findElement(By.id(":f0")).sendKeys("hello");
driver.findElement(By.id("gbg4")).click();
driver.findElement(By.id("gb_71")).click();
}

@After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}

private boolean isElementPresent(By by) {
try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}
}
}


Thanks,
Syam...
venugopald
Active particpant
Active particpant
Posts : 10
Join date : 2012-06-11

Re: How to automated gmail to send email by using Selenium?

on Wed Jul 04, 2012 5:59 pm
HI
Place this code above the error comment

driver.switchTo().frame("canvas_frame");


u have to switch to this frame to perform anything in gmail. i tried it & succeded
syamp
Posts : 8
Join date : 2012-03-09

Re: How to automated gmail to send email by using Selenium?

on Wed Jul 04, 2012 7:45 pm
Thanks venugopal
now i am facing another issue that is unable to write the message in the gamil body. please help me on this.
---------


venugopald wrote:HI
Place this code above the error comment

driver.switchTo().frame("canvas_frame");


u have to switch to this frame to perform anything in gmail. i tried it & succeded
venugopald
Active particpant
Active particpant
Posts : 10
Join date : 2012-06-11

Re: How to automated gmail to send email by using Selenium?

on Wed Jul 04, 2012 7:55 pm
do one thing take xpath of the body using Firebug and replace the previous body xpath using the latest one. definetely it works...
avatar
rohit13
Master
Master
Posts : 180
Join date : 2012-03-29
Age : 31
Location : INDIA
http://radical-qa.blogspot.in/

Re: How to automated gmail to send email by using Selenium?

on Wed Jul 04, 2012 8:41 pm
Try out this one
Code:
driver.findElement(By.xpath("//body")).sendKeys("Test Content");
OR
Code:
driver.findElement(By.cssSelector("body[class='editable  LW-avf']")).sendKeys("body text");

_________________
Radical QA
http://radical-qa.blogspot.in/
mckiranlieutenant007@gmai
Posts : 4
Join date : 2013-04-22

Re: How to automated gmail to send email by using Selenium?

on Mon Apr 22, 2013 2:06 am
I have a smart solution for this using Selenium IDE. I could go to composer text area by just using its class (class=editable LW-avf).

I am unable to add any external links here, if anyone need thee code please contact me on my email.
Sponsored content

Re: How to automated gmail to send email by using Selenium?

Back to top
Permissions in this forum:
You cannot reply to topics in this forum