java - 如何使用 Selenium 在撰写部分中单击更多选项?
问题描述
我正在练习 Selenium Java 上的编码。
我单击撰写部分并输入收件人、主题和正文,并尝试单击虚线以将标签选择为社交,但无法单击该部分。
请找到以下代码。
@Test
public void testSendEmail() throws Exception {
driver.get("https://mail.google.com/");
WebElement userElement = driver.findElement(By.id("identifierId"));
userElement.sendKeys(properties.getProperty("username"));
driver.findElement(By.id("identifierNext")).click();
Thread.sleep(1000);
WebElement passwordElement = driver.findElement(By.name("password"));
passwordElement.sendKeys(properties.getProperty("password"));
driver.findElement(By.id("passwordNext")).click();
Thread.sleep(1000);
WebElement composeElement = driver.findElement(By.xpath("//div[contains(text(),'Compose')]"));
composeElement.click();
WebDriverWait wait=new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//textarea[@name='to']")));
//To Field
driver.findElement(By.name("to")).clear();
driver.findElement(By.name("to")).sendKeys(String.format("%s@gmail.com", properties.getProperty("username")));
//Subject Field
String emailSubject = properties.getProperty("email.subject");
driver.findElement(By.xpath("//input[@name='subjectbox']")).sendKeys(emailSubject);
//Body
String emailBody = properties.getProperty("email.body");
driver.findElement(By.xpath("//div[@class='Ar Au']//div")).sendKeys(emailBody);
//More options----Line where I am unable to click on the dotted lines to mark label as social.
driver.findElement(By.xpath("//div[@id=':q6']/div[2]")).click();
Thread.sleep(2000);
//Hover on Label
WebElement Label=driver.findElement(By.xpath("(//div[contains(text(),'Label')])[1]"));
WebElement Social=driver.findElement(By.xpath("//div[contains(text(),'Social')]"));
Actions a=new Actions(driver);
a.moveToElement(Label);
Thread.sleep(5000);
a.moveToElement(Social).click().build().perform();
Thread.sleep(5000);
//Click On Send
driver.findElement(By.xpath("//*[@role='button' and text()='Send']")).click();
解决方案
不看html很难回答。代替:
Actions a=new Actions(driver);
a.moveToElement(Label);
Thread.sleep(5000);
a.moveToElement(Social).click().build().perform();
尝试这个:
a.moveToElement(Label).build().perform();
waitUntil(ExpectedConditions.elementToBeVisible(Social)).click();
推荐阅读
- swift - 滚动到 WKWebView 的底部,macOS?
- javascript - 如何在 Angular 6 中格式化日期?
- angular - JSONP 调用成功,但出现错误:JSONP 注入脚本未调用回调
- python - 如何对 1000 个独特的时间序列数据进行数据探索?
- amazon-web-services - 如何在 AWS Lambda 中正确创建身份验证中间件
- c++ - GTest:使用 std::function 参数化测试时的 Valgrind 警告
- python - sklearn中字母的N-gram
- python - 尝试使用枕头/PIL 库时不理解此 FileNotFoundError
- c# - 具有展开和聚合的 MongoDB 性能
- php - mysqli更新查询未捕获异常