尝试使用Selenium服务器方法点击元素时出现问题"点击"。 重点是: 有时一些测试失败,因为元素硒之一没有被罚款,但在实际 - 硒中点击元素之前元素真正显示在页面中。在点击之前我检查isElementVisible& iselementPresent但它没有帮助。我也在所有点击之前放了Thread.sleep。## Heading ## 这是我对WaitAndClick的代码的和平
public void waitAndClick(String locator) throws Exception {
long ts = System.currentTimeMillis();
for (int second = 0;; second++) {
if (selenium.isElementPresent(locator) == true && selenium.isVisible(locator) == true) {
//System.out.println("click true");
Thread.sleep(250);
selenium.click(locator);
//selenium.fireEvent(locator,"click");
//selenium.fireEvent(locator, "click");
break;
} else {
//System.out.println("click false");
Thread.sleep(100);
}
if (System.currentTimeMillis() - ts > 20000) {
throw new Exception("WaitAndClick for " + locator + " out off 20 seconds");
}
}
}