【发布时间】:2015-07-12 16:04:30
【问题描述】:
我正在尝试登录我的 gmail,撰写电子邮件并使用 gmail 发送。我已经编写了以下代码,但无法找到 COMPOSING 按钮单击。
package Selenium;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Email {
public static void main(String[] args) {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in");
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("/html/body/div/div[3]/div[1]/div/div/div/div[1]/div[2]/a")).click();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.findElement(By.id("Email")).sendKeys("abhilash.rout8@gmail.com");
driver.findElement(By.id("Passwd")).sendKeys("password");
driver.findElement(By.id("signIn")).click();
driver.manage().timeouts().pageLoadTimeout(2, TimeUnit.MINUTES);
driver.findElement(By.xpath("//div[contains(text(),'COMPOSE')]")).click();
driver.findElement(By.xpath("/html/body/div[14]/div/div/div/div[1]/div[2]/div[1]/div[1]/div/div/div/div[3]/div/div/div[4]/table/tbody/tr/td[2]/form/div[2]/div")).sendKeys("abhilash.rout8@gmail.com");
driver.findElement(By.id("1ys")).sendKeys("Hello");
driver.findElement(By.id("1zu")).sendKeys("Selenium Email");
driver.findElement(By.id("1yi")).click();
}
}
我在(By.xpath("//div[contains(text(),'COMPOSE')]")).click(); 收到错误
我也尝试通过绝对路径和 css 选择器找到该元素。当 Gmail 仍在加载电子邮件页面时,控制台中会出现此错误,尽管我已经让它等待 2 分钟,我可以看到它在页面尚未加载时尝试执行下一行。
【问题讨论】: