简体   繁体   English

硒-无法在gmail中找到COMPOSE按钮

[英]selenium - unable to locate the COMPOSE button in gmail

I am trying to log in to my gmail, compose an email and send it using gmail. 我正在尝试登录我的gmail,撰写电子邮件并使用gmail发送。 I have written the below code but it is failing in locating the COMPOSING button click. 我已经编写了以下代码,但是找不到“ 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();
    }
}

I am getting the error on (By.xpath("//div[contains(text(),'COMPOSE')]")).click(); 我收到(By.xpath("//div[contains(text(),'COMPOSE')]")).click();

I have also tried to find that element by absolute path and css selector also. 我也试图通过绝对路径和CSS选择器来查找该元素。 This error comes in the console when the the Gmail is still loading the email page though I have given it to wait for 2 minutes, I can see it tries to execute the next line when the page is yet to load. 尽管我已经让Gmail等待2分钟,但Gmail仍在加载电子邮件页面时,控制台中会出现此错误,我可以看到它试图在页面尚未加载时执行下一行。

You an try using: 您可以尝试使用:

WebElement link = driver.findElement(By.linkText("COMPOSE"));

Just a suggestion: 只是一个建议:

Automating Gmail by using the basic html view is a lot more easier than using the regular view. 通过使用基本的html视图自动化Gmail比使用常规视图要容易得多。 When you try to compose an email in the regular view, the small window that pops up has an id that is dynamically generated. 当您尝试在常规视图中撰写电子邮件时,弹出的小窗口具有一个动态生成的ID。 This would not be the case in the basic html view. 在基本的html视图中情况并非如此。 You can load gmail in the basic html view by launching the below url: 您可以通过启动以下url在基本html视图中加载gmail:

https://mail.google.com/mail/u/0/h/s32qz81kdosc/?zy=h&f=1 https://mail.google.com/mail/u/0/h/s32qz81kdosc/?zy=h&f=1

After logging into the above url, you can find the Compose email link by: 登录上述网址后,您可以通过以下方式找到“撰写电子邮件”链接:

wait.until(ExpectedConditions.presenceOfElementLocated(By.linkText("Compose Mail")));
WebElement lnkComposeMail = driver.findElement(By.linkText("Compose Mail"));
lnkComposeMail.click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM