Skip to content

Instantly share code, notes, and snippets.

@TopherGopher
Forked from alnutile/behat.inc.php
Last active January 3, 2016 09:59
Show Gist options
  • Save TopherGopher/8446617 to your computer and use it in GitHub Desktop.
Save TopherGopher/8446617 to your computer and use it in GitHub Desktop.
/**
* Sets an iFrame ID to no_name_iframe if there is no ID. You can then add a Switch to iFrame step after it using the na_name_iframe ID.
*
* @Given /^I the set the iframe located in element with an id of "([^"]*)"$/
*/
public function iSetTheIframeLocatedInElementWithAnIdOf($element_id) {
$element = $this->getMainContext()->getSession()->getPage()->findById($element_id);
if ($element == NULL) {
throw new \Exception(sprintf("Element with ID '%s' not found", $element_id));
}
$javascript = <<<JS
(function(){
var elem = document.getElementById('$element_id');
var iframes = elem.getElementsByTagName('iframe');
var f = iframes[0];
f.id = "no_name_iframe";
})()
JS;
$this->getMainContext()->getSession()->executeScript($javascript);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment