[英]How to automate new gmail UI to send email by using Selenium IDE?
當前的gmail UI已更改,它會在彈出的DIV中打開,並且每個新的撰寫窗口的ID參數都會更改。 任何人都可以嘗試給我代碼嗎?
您可以使用XPath完成所有操作(使用By.xpath("xpath expression")
查找):
"//div[text()='COMPOSE']"
) "//textarea[@name='to']"
"//input[@name='subjectbox']"
"//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.