I'm testing a page with an iFrame whose contents are generated by JavaScript dynamically. I have to wait for the iFrame loaded completely to make sure that all the elements are present. I tried the following code, it didn't work.
WebDriver frame = wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("frmMain"));
I also tried to wait for some element in the iFrame to be present. It didn't work, neither.
Any help would be greatly appreciated, thanks!
You can use Web Driver Wait and Expected Condition class to achieve this. Try this code. WebDriverWait wait = new WebDriverWait(driver,10); wait. until(ExpectedConditions.
We can wait until the page is completely loaded in Selenium webdriver by using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method.
Select any element on IFrame which takes maximum time to load e.g. any button or image and the wait using the following code.
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.visibilityOfElementLocated((By
.name("element"))));
Or rather you can wait for for iFrame to appear and then switch to it and then use the above statement !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With