php - setting iframe ID via fancybox2 to allow webdriver switchTo()->frame(id) -
i'm using fancybox2 create iframes can't see way of setting id of iframe gets created, preventing me using php-webdriver , selenium test contents of iframe.
simplified version of code:
<a href="iframe.html" class="various fancybox.iframe">iframe</a> <script> $(document).ready(function() { $(".various").fancybox() }); </script>
which works, using chrome's inspector, iframe (this time) generated id of fancybox-frame1443817733402
, appears random. means when try use php-webdriver switch frame (having clicked link create iframe), can't predict frame's id pass in:
$frame_id = 'fancybox-frame1443817733402'; // can't predict in advance $driver->switchto()->frame($frame_id);
the iframe generated class of fancybox-iframe
calls
$iframe = $driver->findelement(webdriverby::class("fancybox-iframe"))
return nothing.
i've tried using fancybox2's afterload
callback try explicitly setting iframe's id before trying switch frame id, fails (i think because current
object, not element?)
$(".various").fancybox({ afterload: function(current, previous) { //console.log(current); current.attr('id', 'rob'); }});
is there way of explicitly setting iframe's id can switch via selenium/webdriver? or there simpler way of doing this?
i don't know setting frame id here, can switch frame via xpath (such //frame):
protected webelement gotoiframebyxpath(final string iframexpath) { if (driver.findelements(by.xpath(iframexpath)).size() > 0) { // find elements exception isn't thrown if not found webelement contentframe = driver.findelement(by.xpath(iframexpath)); driver.switchto().frame(contentframe); return contentframe; } else { system.out.println("unable find " + iframexpath); } return null; }
Comments
Post a Comment