The current gmail UI has changed, it opens in a pop up DIV and the ID parameters are changing for each new compose window. Can anyone try to give me the code?
You can do all using XPath (find using By.xpath("xpath expression")
):
- Open the gmail page
- Login as usual
- Click on compose button (its XPath expression:
"//div[text()='COMPOSE']"
) - (The email dialog will pop up)
- Type (send keys) the addesses in the "To" text area:
"//textarea[@name='to']"
- Type (send keys) the subject to the "Subject" input:
"//input[@name='subjectbox']"
- Type (send keys) the email content to the editable div:
"//div[@class='gmail_default']"
(or"//div[@aria-label='Message Body']"
), as it seems they changed their HTML recently) - Hit send:
"//div[text()='Send']"
I found the below solution:
< tr>
<td>setTimeout</td>
<td>3000</td>
<td></td>
< /tr >
< !--open command usually waits for 30 secs, so we are now asking it to wait for only 3 secs-->
< tr>
<td>open</td>
<td>/mail/u/0/?shva=1#inbox?compose=new</td>
<td></td>
< /tr>
< tr>
<td>type</td>
<td>//table/tbody/tr[1]/td[2]/div/div/textarea</td>
<td>McKiran@example.com</td>
< /tr>
< tr>
<td>type</td>
<td>name=subjectbox</td>
<td>Test</td>
< /tr>
< tr>
<td>type</td>
<td>class=editable LW-avf</td>
<td>Hi All<br/>Hope the test is successful. <br/><br/><i> Lovingly, </i></br><b>McKiran.</b></td>
< /tr>
< tr>
<td>click</td>
<td>class=T-I J-J5-Ji aoO T-I-atl L3</td>
<td></td>
< /tr>
Use selenium webdrier
go throw the below link
http://ngowda.blogspot.in/2014/01/uploading-file-in-e-commerce-site-using.html
public static void main(String[] args) throws InterruptedException { System.setProperty("webdriver.chrome.driver","D:\Selenium\SeleniumWork\seleniumDrivers\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get("https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/#identifier"); if(driver.findElement(By.xpath(".//[@id='Email']")).isEnabled()) { driver.findElement(By.xpath(".//[@id='Email']")).sendKeys("youremailid"); driver.findElement(By.xpath(".//*[@id='next']")).click(); } Thread.sleep(5000); WebElement menu = driver.findElement(By.xpath(".//input[@type='password']")); if(menu.isEnabled()) {
System.out.println("Hello world");
menu.sendKeys("emailidpassword");
driver.findElement(By.xpath(".//*[@id='signIn']")).click();
}
Thread.sleep(5000);
driver.findElement(By.xpath(".//div[contains(text(),'COMPOSE')]")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//textarea[@name='to']")).sendKeys("@gmail.com");
driver.findElement(By.xpath("//input[@name='subjectbox']")).sendKeys("Sample");
driver.findElement(By.xpath("//div[@aria-label='Message Body']")).sendKeys("HI this is simple message"); driver.findElement(By.xpath("//div[text()='Send']")).click();
}
来源:https://stackoverflow.com/questions/16135329/how-to-automate-new-gmail-ui-to-send-email-by-using-selenium-ide