I have this code:
WebElement iframeElement = driver.findElement(By.xpath(xpIframe));
driver.switchTo().frame(iframeElement);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpLucka)));
driver.findElement(xpLucka).click(); //this click fails
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpSvara))); //TimeoutException
driver.findElement(xpSvar).click();
driver.findElement(xpSvara).click();
Frequently it fails on the line with the comment //TimeoutException. When I look at the state of the web page in the browser that is left open it is clear that the click on the line before it has failed. This is confusing. The element clearly is there, I find it without problems in the web inspector and the wait.until on the previous line obviously succeeds.
The next thing I want to make sure doesn't fail is the switchTo()
statement. How can I verify a switchTo-call?
- Note that is also succeeds frequently. I just ran this in a loop 9 times, it failed 5 times "but" succeeded 4 times.
- Any other suggestions why this might happen are of course very welcome.