Created
December 16, 2012 15:07
-
-
Save ypresto/4308281 to your computer and use it in GitHub Desktop.
casperjs iframe test example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
</head> | |
<body> | |
<iframe name="ad_iframe" src="./casper_test.html" /> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global require:false */ | |
var casper = require('casper').create(); | |
casper.start('./iframe_test.html'); | |
casper.withFrame('ad_iframe', function () { | |
this.test.assertUrlMatch(/casper_test\.html/, 'i am on inside of iframe'); | |
this.test.assertVisible('#hoge', 'hoge is clickable'); | |
this.clickLabel('clickable hoge'); | |
}); | |
casper.withFrame('ad_iframe', function () { | |
this.test.assertUrlMatch(/#!\/hoge/, 'hash changed to hoge'); | |
this.test.assertNotVisible('#fuga', 'fuga is not clickable'); | |
this.clickLabel('unclickable fuga'); | |
}); | |
casper.withFrame('ad_iframe', function () { | |
this.test.assertUrlMatch(/#!\/hoge/, 'hash not changed to fuga'); | |
this.echo("I'm sorry, it's clickable..."); | |
}); | |
casper.run(); |
I have the same problem trying to select an iframe with no name. Any suggestions?
I have the same problem too, any ideas? many thanks.
Use casper.page.switchToChildFrame(0) for the first iframe
You can call withFrame with an index for those iframes with no name attribute:
casper.withFrame(0, function() {
this.test.assertTitle('FRAME TITLE');
});
You just has to figure out the index of your desired iframe. I usually do it by inspecting the html code of the page.
Is there any way we can fill up a form inside casper.withFrame() for example this.sendKeys() or this.fill() or this.fillSelectors()?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if iframe no name, what can i do?