如何使用Behat/Mink切换到动态命名的iframe [英] How to switch to dynamically named iframe with Behat/Mink

查看:84
本文介绍了如何使用Behat/Mink切换到动态命名的iframe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

单击按钮时生成的iFrame的书写测试. iFrame名称和ID相似,但是是动态生成的.我以前已经成功使用过"switchToiFrame".

Writing test for an iFrame generated when a button is clicked. The iFrame name and id are similar but generated dynamically. I have used "switchToiFrame" successfully before.

<div class="bbbb-frame-container" style="height: 400px; width: 665px; margin-top: -200px; margin-left: -332.5px;">
<div class="user-support-frame-close-container" style="display: block;">
<div class="user-support-frame-close">Close</div>
</div>
<iframe id="poplock_default9636_priv" frameborder="0" name="poplock_default9636_priv" src="blah.blaag.com">
<!DOCTYPE html>

.....................

.....................

poplock_defaultNNNN_priv是我想切换到的动态生成的iFrame.

The poplock_defaultNNNN_priv is the dynamically generated iFrame that I would like to switch to..

推荐答案

首先,使用一种查找方法.如果它是页面上唯一的iframe(或第一个),请使用find() method.如果不是,则必须使用findAll()并依赖顺序(因为没有可以搜索的独特属性).

First, find an iframe with one of the find methods. If it's the only iframe on the page (or the first one) use the find() method. If it's not, you'll have to use findAll() and rely on the order (since there's no distinct attribute you could search for).

找到iframe后,您可以使用 getAttribute 获取其名称,然后使用 switchToIframe ...好,切换到iframe.

Once you find your iframe, you can use getAttribute to get its name and then use switchToIframe to... well, switch to the iframe.

这篇关于如何使用Behat/Mink切换到动态命名的iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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