簡體   English   中英

如何使用Selenium IDE自動化新的gmail UI發送電子郵件?

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

當前的gmail UI已更改,它會在彈出的DIV中打開,並且每個新的撰寫窗口的ID參數都會更改。 任何人都可以嘗試給我代碼嗎?

您可以使用XPath完成所有操作(使用By.xpath("xpath expression")查找):

  • 打開Gmail頁面
  • 像往常一樣登錄
  • 單擊撰寫按鈕(其XPath表達式: "//div[text()='COMPOSE']"
  • (彈出電子郵件對話框)
  • 在“收件人”文本區域中鍵入(發送鍵)addesses: "//textarea[@name='to']"
  • 鍵入(發送鍵)主題到“主題”輸入: "//input[@name='subjectbox']"
  • 輸入(發送密鑰)電子郵件內容到可編輯的div: "//div[@class='gmail_default']" (或"//div[@aria-label='Message Body']" ),因為看起來他們最近更改了他們的HTML)
  • 點擊發送: "//div[text()='Send']"

我找到了以下解決方案:

<tr>

<td>setTimeout</td>
<td>3000</td>
<td></td>

</ tr>

<! - open命令通常等待30秒,所以我們現在要求它等待3秒鍾 - >

<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()窗口()最大化(); 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 = '下一個']”))點擊(); 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 [文本()= '發送']”))點擊();

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM