2013-11-04 130 views
0

我是一個學習者,我試圖從新gmail編寫郵件,但無法在撰寫窗口打開後輸入id列表,試圖切換幀方法,但沒有成功在尋找領域本身,你能幫我解決這個問題。撰寫郵件來自Selenium WebDriver

謝謝。

+2

您必須向我們展示您所嘗試的內容,以便我們可以指引您朝正確的方向發展。但請注意,gmail很難與W​​ebdriver一起使用,我相當肯定它的創建方式很難自動化。 –

回答

0

以下是從GMail帳戶編寫郵件的示例。

package testCase; 

import java.awt.AWTException; 
import java.awt.Robot; 
import java.awt.Toolkit; 
import java.awt.datatransfer.StringSelection; 
import java.awt.event.KeyEvent; 
import java.io.File; 

import org.junit.After; 
import org.junit.Before; 
import org.junit.Test; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 

public class GmailFileUpload 
{ 
    WebDriver driver = null; 
    WebElement element = null; 

    @Before 
    public void setUp() throws Exception 
    { 
     File file = new File("G:\\Selenium\\All_Jars\\chromedriver.exe"); 
     System.setProperty("webdriver.chrome.driver", file.getAbsolutePath()); 
     driver = new ChromeDriver(); 
     driver.manage().window().maximize(); 
    } 

    @Test 
    public void test() throws InterruptedException, AWTException 
    { 
     driver.get("https://www.google.co.in"); 
     driver.findElement(By.linkText("Sign in")).click(); 
     driver.findElement(By.id("Email")).sendKeys("[email protected]"); 
     driver.findElement(By.id("Passwd")).sendKeys("your gmail password"); 
     driver.findElement(By.id("signIn")).click(); 
     driver.findElement(By.linkText("Gmail")).click(); 
     driver.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click(); //Click on Compose button 
     Thread.sleep(5000); 
     driver.findElement(By.xpath("//textarea[@name='to']")).sendKeys("[email protected]"); // write mail id to whom do you want to send an email 
     driver.findElement(By.xpath("//input[@name='subjectbox']")).sendKeys("want to say Hello"); // write subject 
     element = driver.findElement(By.xpath("//div[@class='Ar Au']//div")); 
     element.click(); 
     element.sendKeys("Hi Avinash"); //type in message body 
     driver.findElement(By.xpath("//div[contains(text(),'Send')]")).click(); //click on send button 
    } 
}