【发布时间】:2017-09-08 12:30:27
【问题描述】:
在我的测试脚本中必须为每次执行编写 waiFor(5),否则测试失败。 我正在使用 POM,并且有单独的类。
@Test(priority=2)
public void TestMedical() throws InterruptedException {
waitFor(5);
MedicalPage medicalpage = new MedicalPage(driver);
waitFor(5);
medicalpage.PhysicianName(Repo.getProperty("fName"));
medicalpage.seteditableLastName(Repo.getProperty("lName"));
waitFor(5);
medicalpage.setPhone(Repo.getProperty("Phone"));
waitFor(5);
medicalpage.setEmail(Repo.getProperty("Email"));
}
这是我的登录页面(对象)-
// Created methods in this page, and using Testng trying to call all the below methods. But getting failure message Unable to Locate Element, If there is no wait time watFor(5). With Wait time its running fine.In base page have explicit wait time method, but its not working. After input the data in text field when i click on submit button page is doing some Java Script or Ajax.
Ajax 调用最多需要 60 秒。
driver.findElement(firstName).click();
driver.findElement(editableFirstName).clear();
driver.findElement(editableFirstName).click();
driver.findElement(editableFirstName).sendKeys(fName);
}
【问题讨论】:
-
一些更多信息会有所帮助:测试如何失败(例如有什么样的异常),是否有在线示例页面可以查看页面源代码,页面是否在做一些填充输入元素时的 JavaScript 内容(例如 AJAX),...
-
那么简单的事情没有提供任何其他细节,尝试隐式等待 5 秒。但这根本不是理想的解决方案……
-
我不记得确切但有一些
setSpeed()方法延迟执行所有后面的语句指定的延迟。 -
欢迎来到 Stack Overflow!请阅读How to Ask。请提供您尝试过的代码和执行结果,包括任何错误消息等。同时提供指向页面和/或相关 HTML 的链接。
-
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);然后删除所有等待的。隐式等待将等待您给它的任何时间限制,但一旦收到响应就会继续执行脚本,因此没有强制延迟。