尝试使用CasperJS在iframe中跟踪链接 [英] Trying to follow a link in an iframe using CasperJS
问题描述
我正在尝试使用 CasperJS 跟随iframe中的链接,但我无法
I'm trying to use CasperJS to follow a link that's in an iframe but I can't seem to get at the iframe's document.
这里是使用我发现的iframe示例页面进行的测试。
第三个iframe具有name属性,Casper的frame方法需要该属性。 Casper API
Here's a test using an iframe example page I found. The third iframe has a name attribute which I need for Casper's frame method. Casper API
var casper = require('casper').create();
casper.start('http://nunzioweb.com/iframes-example.htm');
casper.withFrame('frame', function(){
this.echo('Page url is ' + this.getCurrentUrl());
this.echo(this.getHTML());
});
casper.run();
页面网址返回 http://nunzioweb.com/lyrics/455Rocket.html就像我期望的那样,但是返回的html是包裹iframe的页面。
The page url comes back with "http://nunzioweb.com/lyrics/455Rocket.html" as I expected but the returned html is the page wrapping the iframe.
任何想法我都可以进入iframe以便点击[我在页面上m实际上是用]来完成的??
Any idea how I can get into the iframe so I can click a link [on the page I'm actually doing this with]?
推荐答案
由于某些原因 .getHTML()
在这里不起作用,您必须直接从 WebPage
实例获取页面HTML
。
For some reason .getHTML()
doesn't work here, you have to get the page HTML
directly from the WebPage
instance.
var casper = require('casper').create();
casper.start('http://nunzioweb.com/iframes-example.htm');
casper.withFrame('frame', function(){
this.echo('Page url is ' + this.getCurrentUrl());
this.echo(this.page.content);
});
casper.run();
我将致力于解决这个问题。
I'll be working on that issue.
单击链接,例如。在您的iframe示例中的光滑城市
上:
To click on a link, eg. on the Slick City
one in your iframe example:
var casper = require('casper').create();
casper.start('http://nunzioweb.com/iframes-example.htm');
casper.withFrame('frame', function() {
this.echo('Page url is ' + this.getCurrentUrl());
this.clickLabel('Slick City');
});
casper.waitForPopup('slickcitydown.htm').withPopup('slickcitydown.htm', function() {
this.echo('New page url is ' + this.getCurrentUrl());
});
casper.run();
得出:
$ casperjs test.js
Page url is http://nunzioweb.com/lyrics/455Rocket.html
New page url is http://nunzioweb.com/slickcitydown.htm
这篇关于尝试使用CasperJS在iframe中跟踪链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!