我对所有Automated Testing事情都很陌生,最近我遇到了selenium的问题,因为有时候找不到某些输入字段/按钮。
我为页面中的每个元素添加了显式等待,因此测试应该等待该元素出现在屏幕上,但有时候随机无法执行此操作。我将在一个简单的测试中附加selenium抛出的最新错误。
这是我试图运行并随机失败的测试之一:
@Test
public void createTaskTest(){
generateTestEnvironmentSalesForceHomePage();
this.home.clickTasksTab();
generateTestEnvironmentTaskPage();
this.taskspage.clickNewTask();
generateTestEnvironmentNewTask();
this.newtask.setDateField("12/30/2016");
this.newtask.setCostField("1500");
this.newtask.setType("Personal Appointment");
this.newtask.setPaymentType("End of the day");
this.newtask.setDoctor("House");
this.newtask.submitTask();
Assert.assertTrue(this.newtask.checkDetailsPage());
}
selenium抛出的错误:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for visibility of element located by By.cssSelector: span.dateOnlyInput>input (tried for 130 second(s) with 500 MILLISECONDS interval)
以下是查找“缺失”日期输入的方法:
public void setDateField(String date){
WebDriverWait wait = new WebDriverWait(this.driver,130);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span.dateOnlyInput>input")));
this.driver.findElement(By.cssSelector("span.dateOnlyInput>input")).sendKeys(date);
}