This is my code
do {
try {
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(xpLand)));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
driver.findElement(By.xpath(xpLand)).click();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Thread.sleep(500);
if (i > 20 ) {
break;
}
i++;
} while (driver.findElements(By.xpath(xpLand)).size() > 0);
URL https://win.milwaukeetool.eu/#
elementToBeClickable
works (I have also tried different versions of visible
and other alternatives), no exception is thrown. click
also works, but nothing is triggered by the click. Finally, the while
-condition is also true
.
What happens is that the page loads (outside of the code above), clickable is satisfied, click doesn't throw an exception, the while-condition is greater than 0 (if the click would have worked a new page would load and it would be 0), and then it starts over.
Screen size 1440 x 900-23 (23 = height of menubar)
xpLand = //img [@src='/img/countries/se.svg']
The weird thing is that it works about half of the time but fails the other half (I just run it around 400 times and it worked and failed about 200 times each). If I manually click the link when my code is stuck, the click leads to the expected result.
It is like it sometimes is getting stuck. I have an outer loop (not visible above) that runs ten times with the same driver and after that launches a new driver. If it "gets stuck", it won't work again until these ten loops are finished and the new driver is launched. Then it might work for 5-10 times, until it again gets stuck.
Using Chrome/chromedriver.