Selenium WebDriver:如何等待iFrames完全加载? [英] Selenium WebDriver: How to wait for iFrames to load completely?

查看:1963
本文介绍了Selenium WebDriver:如何等待iFrames完全加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个带有iFrame的页面,其内容由JavaScript动态生成。我必须等待完全加载的iFrame以确保所有元素都存在。我尝试了以下代码,它没有用。

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"));

我还试图等待iFrame中的某些元素出现。它没有用,也没用。



非常感谢任何帮助,谢谢!

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!

推荐答案

选择IFrame上任何需要最长时间加载的元素,例如任何按钮或图像以及等待使用以下代码。

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"))));

或者你可以等待iFrame出现然后切换到它然后使用上面的语句!

Or rather you can wait for for iFrame to appear and then switch to it and then use the above statement !

这篇关于Selenium WebDriver:如何等待iFrames完全加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆