I have a problem when try to click for element using Selenium server method "click". The point is: sometimes some test failed, because one of element selenium doesnt fined, but in real - selenium clicked for element before the element is real displayed in page. Before the click i check isElementVisible & iselementPresent but it is doesnt help. Also i put Thread.sleep before all click.## Heading ## This is my peace of code for 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");
}
}
}