我是第一次进行自动化测试,我希望能够自动化 gmail 并发送带有附件的电子邮件。我正在使用 selenium 网络驱动程序、黄瓜和谷歌浏览器来运行测试。我的 IDE 是 IntelliJ。我的测试一直有效,直到我必须附加文件:
public void givenOnAmazonProductPage() throws Throwable {
setupSeleniumWebDrivers();
goTo(PRODUCT_URL);
driver.findElement(By.id("identifierId")).sendKeys("username");
driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
Thread.sleep(3000);
driver.findElement(By.name("password")).sendKeys("password");
driver.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
Thread.sleep(4000);
goTo(PRODUCT_URL);
//driver.wait().until(ExpectedConditions.elementToBeClickable(By.xpath(".//textarea[contains(@aria-label, 'To')]")));
driver.findElement(By.xpath(".//textarea[contains(@aria-label, 'To')]")).click();
driver.findElement(By.xpath(".//textarea[contains(@aria-label, 'To')]")).sendKeys("abcd@gmail.com");
driver.findElement(By.name("subjectbox")).click();
driver.findElement(By.name("subjectbox")).sendKeys("efgh");
driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).click();
driver.findElement(By.xpath("(.//*[@aria-label='Message Body'])[2]")).sendKeys("This is an auto-generated mail");
//driver.findElement(By.xpath("//span[@class='T-I J-J5-Ji T-I-KE L3']")).click();
//driver.close();
//click on attachment
driver.findElement(By.xpath("//div[@class='a1 aaA aMZ']")).click();
//use autoit tool to attach a file
这是我尝试附加桌面上的文件但它似乎不起作用的地方
Runtime.getRuntime().exec("C:Desktop/6c3bfdec92fad54896275802f938bd83.29.jpg");
// enter the file path onto the file-selection input field
Thread.sleep(10000); //wait for 10sec to upload file
}
有谁知道我在附加文件时做错了什么?