How to automate new gmail UI to send email by using Selenium IDE?

强颜欢笑 提交于 2019-12-03 09:09:42

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>

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();

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!