Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver: How to wait for iFrames to load completely?

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!

like image 497
user2432405 Avatar asked Aug 28 '13 11:08

user2432405


People also ask

How do you wait for a frame to load?

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.

Which method will wait till page gets loaded fully?

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.


1 Answers

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 !

like image 183
Abhishek Singh Avatar answered Sep 17 '22 11:09

Abhishek Singh