如何使用Behat/Mink切换到动态命名的iframe

Ian*_*ins 3 iframe behat mink selenium-webdriver

为单击按钮时生成的iFrame编写测试.iFrame名称和ID类似,但动态生成.我以前成功使用过"switchToiFrame".

<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>
Run Code Online (Sandbox Code Playgroud)

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

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

Jak*_*las 8

首先,使用其中一种查找方法查找iframe .如果它是页面上唯一的iframe(或第一个),请使用find() method.如果不是,您将不得不使用findAll()并依赖订单(因为您没有可以搜索的明确属性).

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