Selenium webdriver 从SeleniumWebDriver撰写邮件

Selenium webdriver 从SeleniumWebDriver撰写邮件,selenium-webdriver,Selenium Webdriver,我是一名学习者,我正在尝试从新的gmail撰写邮件,但在撰写窗口打开后无法在列表中输入id,尝试切换框架方法,但未能成功定位“收件人”字段本身,您能在这方面帮助我吗 谢谢。这个博客包含了很多这样做的例子: 这就是你需要的吗?下面是从GMail帐户撰写邮件的示例 package testCase; import java.awt.AWTException; import java.awt.Robot; import java.awt.Toolkit; import java.awt.datat

我是一名学习者,我正在尝试从新的gmail撰写邮件,但在撰写窗口打开后无法在列表中输入id,尝试切换框架方法,但未能成功定位“收件人”字段本身,您能在这方面帮助我吗


谢谢。

这个博客包含了很多这样做的例子:


这就是你需要的吗?

下面是从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("aavinashpande@gmail.com");
        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("aavinashpande@gmail.com"); // 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
    }
}

你必须向我们展示你的尝试,这样我们才能为你指明正确的方向。请注意,gmail很难与Webdriver一起使用,我敢肯定它是以一种难以自动化的方式创建的。请在代码中添加注释或描述以帮助其他人理解。
package basic;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class mozilaProj {

    public static void main(String[] args) throws InterruptedException {
        String path = "D:\\harsh\\Selenium data\\geckodriver.exe";  //location where your driver is placed.
            System.setProperty("webdriver.gecko.driver", path);  
        WebDriver wd=new FirefoxDriver();
        wd.navigate().to("http://accounts.google.com");

        wd.findElement(By.id("identifierId")).sendKeys("Your mail ID");
        wd.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/content/span")).click();  // Click on next 
        Thread.sleep(4000);  //wait needed here To get the password page.
        wd.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[1]/div/form/content/section/div/content/div[1]/div/div[1]/div/div[1]/input")).sendKeys("Email Password");  // click on next
        wd.findElement(By.xpath("/html/body/div[1]/div[1]/div[2]/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/content")).click();  //If your page redirect to google security page.
        Thread.sleep(2000);
        wd.findElement(By.cssSelector(".gb_mf > path:nth-child(1)")).click(); //click on google apps tab. 
        wd.findElement(By.cssSelector("#gb23 > span:nth-child(5)")).click();  //click on gmail icon.
        wd.findElement(By.xpath("/html/body/div[7]/div[3]/div/div[2]/div[1]/div[1]/div[1]/div[2]/div/div/div/div[1]/div/div")).click();   // click on compose  

         WebDriverWait wait = new WebDriverWait(wd, 20);   // implement wait here to load all data.
        wait.until(
            ExpectedConditions.visibilityOfElementLocated(By.name("to")));
        wd.findElement(By.name("to")).sendKeys("recepient mail ID");
        wd.findElement(By.id(":mx")).sendKeys("Subject of mail");
        wd.findElement(By.id(":o0")).sendKeys("Mail body "); // type mail body 
        wd.findElement(By.id(":mn")).click();    // Send button click
        Thread.sleep(8000);  // Apply wait for sending mail 
        wd.close();

    }

}