2017-02-21 90 views
1

我能夠成功編寫郵件,但添加了郵件主題..我無法找到任何元素XpathidclassName來鍵入郵件正文。如何在selenium webdriver中輸入Gmail正文文本

我用過: - 鍵入(發送鍵)電子郵件內容到可編輯div:「// div [@ class ='gmail_default']」(或者「// div [@ aria-label ='Message身體']「)了Gmail正文..

driver.findElement(By.xpath("//div[@aria-label='Message Body']")).sendKeys("This is the test email send to test the selenium script."); 

它的工作once..after它停止工作。

請任何人都可以幫忙... ****************** ****************** ******************* ***

public class TestSelenium { 
public static void main(String[] args) throws InterruptedException{ 

    System.setProperty("WebDriver.gecko.driver", "C:\\Users\\Administrator\\geckodriver-v0.14.0-win64\\geckodriver.exe"); 

    FirefoxDriver driver = new FirefoxDriver(); 
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
    driver.get("http://www.gmail.com/"); 

    driver.manage().window().maximize(); 
    WebElement id =driver.findElement(By.xpath(".//*[@id='Email']")); 
    id.click(); 
    id.sendKeys("Email"); 
    WebElement next = driver.findElement(By.xpath(".//*[@id='next']")); 
    next.click(); 
    WebElement psw = driver.findElement(By.id("Passwd")); 
    psw.clear(); 
    psw.sendKeys("Password"); 

    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); 
    WebElement login = driver.findElement(By.xpath(".//*[@id='signIn']")); 
    login.click(); 
    WebElement compose = driver.findElement(By.xpath(".//*[@id=':44']/div/div")); 
    compose.click(); 
    WebElement to = driver.findElement(By.className("vO")); 
    to.sendKeys("Email_id of Receiver"); 
    WebElement sub = driver.findElement(By.className("aoT")); 
    sub.sendKeys("Login Successful"); 
    driver.findElement(By.xpath("//div[@aria-label='Message Body']")).sendKeys("This is the test email send to test the selenium script."); 

    WebElement send = driver.findElement(By.xpath(".//*[@id=':8m']")); 
    send.click(); 

}}

+0

爲什麼不使用Tab將控件從主題移動到消息主體。 –

+0

我試着用TAB也可以,但是Tab給控件發送按鈕.. –

+0

你可以提供一步一步的代碼。 –

回答

0

嘗試使用:sub.sendKeys(Keys.TAB);

0

我已經嘗試了下面的代碼來查找元素,它的工作,我已經測試了4次,它一直工作。

但在此之前,請確保您已經投入足夠的時間來打開撰寫部分。 sendKeys(「Balle Balle」);這是一個簡單的例子。

希望這會幫助你。如果這不能解決你的問題,那麼讓我知道你面臨的錯誤。
謝謝,
Ed D,印度。

相關問題