Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to switch to dynamically named iframe with Behat/Mink

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>

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

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

like image 730
Ian Jenkins Avatar asked May 08 '13 16:05

Ian Jenkins


Video Answer


1 Answers

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).

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

like image 119
Jakub Zalas Avatar answered Feb 14 '23 22:02

Jakub Zalas