Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Phantomjs 单击不带ID的链接或带有casperJS的类_Phantomjs_Casperjs - Fatal编程技术网

Phantomjs 单击不带ID的链接或带有casperJS的类

Phantomjs 单击不带ID的链接或带有casperJS的类,phantomjs,casperjs,Phantomjs,Casperjs,我正在尝试获取此页面左侧菜单上的链接列表: 我要做的第一件事是点击“全部展开”链接(在左上角),这样列表就会展开 我尝试了多种方法以不同的方式使用Xpath,但在此页面上没有成功,这是我最后一次尝试: casper.start('http://www.hpenterprisesecurity.com/vulncat', function() { casper.wait(5000); this.echo("---------- TITLE: "); this.echo(th

我正在尝试获取此页面左侧菜单上的链接列表:

我要做的第一件事是点击“全部展开”链接(在左上角),这样列表就会展开

我尝试了多种方法以不同的方式使用Xpath,但在此页面上没有成功,这是我最后一次尝试:

casper.start('http://www.hpenterprisesecurity.com/vulncat', function() {
    casper.wait(5000);
    this.echo("---------- TITLE: ");
    this.echo(this.getTitle());

});    

casper.thenClick(x('//*[@id="theContentCenter"]/div/p/a[1]/strong[contains(text(),"Expand")]'),function(){
        casper.wait(5000,function(){
        casper.capture("expanded.png");
        });
    });
也许因为页面缺少大多数元素的ID和标签,我的方法就不起作用了

谢谢

设置:

casper = require('casper').create({
    verbose:true,
    logLevel:"debug"
});


casper.userAgent('Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405');
casper.viewport = {width: 1280, height: 720};

var x = require('casper').selectXPath;
幻影JS:1.9.8

casperjs:1.1.0-beta3

资源错误:

[info] [phantom] Starting...
[info] [phantom] Running suite: 2 steps
[info] [phantom] Starting...
[info] [phantom] Running suite: 4 steps
[debug] [phantom] opening url: http://www.hpenterprisesecurity.com/vulncat, HTTP GET
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html, type=Other, willNavigate=true, isMainFrame=true
[debug] [phantom] url changed to "http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html"
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/header.html, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/all.html, type=Other, willNavigate=true, isMainFrame=false
[debug] [phantom] Navigation requested: url=http://www.hpenterprisesecurity.com/vulncat/en/vulncat/intro.html, type=Other, willNavigate=true, isMainFrame=false
ResourceError: {
    "errorCode": 203,
    "errorString": "Error downloading http://www.hpenterprisesecurity.com/vulncat/en/vulncat/css/frame.css - server replied: Not Found",
    "id": 7,
    "url": "http://www.hpenterprisesecurity.com/vulncat/en/vulncat/css/frame.css"
}
ResourceError: {
    "errorCode": 2,
    "errorString": "Connection closed",
    "id": 9,
    "url": "http://www.fortifysoftware.com/images/gui/maincontent.level3.h1.bg.png"
}
[debug] [phantom] Successfully injected Casper client-side utilities
[info] [phantom] Step anonymous 2/4 http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html (HTTP 200)
---------- TITLE:
A Taxonomy of Coding Errors that Affect Security
[info] [phantom] Step anonymous 2/4: done in 770ms.
[info] [phantom] Step _step 3/5 http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html (HTTP 200)
[info] [phantom] Step _step 3/5: done in 770ms.
[info] [phantom] wait() finished waiting for 5000ms.
[info] [phantom] Step _step 4/5 http://www.hpenterprisesecurity.com/vulncat/en/vulncat/index.html (HTTP 200)
[debug] [phantom] Mouse event 'mousedown' on selector: xpath selector: //*[@id="theContentCenter"]/div/p/a[1]/strong[contains(text(),"Expand")]
CasperError: Cannot dispatch mousedown event on nonexistent selector: xpath selector: //*[@id="theContentCenter"]/div/p/a[1]/strong[contains(text(),"Expand")]
  /usr/lib/node_modules/casperjs/modules/casper.js:1355 in mouseEvent
  /usr/lib/node_modules/casperjs/modules/casper.js:462 in click
  /usr/lib/node_modules/casperjs/modules/casper.js:1793 in _step
  /usr/lib/node_modules/casperjs/modules/casper.js:1553 in runStep
  /usr/lib/node_modules/casperjs/modules/casper.js:399 in checkStep
Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/lib/node_modules/casperjs/bin/bootstrap.js. Domains, protocols and ports must match.

a) 您使用哪个PhantomJS版本?b) 请注册到
resource.error
page.error
remote.message
casper.page.onResourceTimeout
事件()。也许有错误。c) 是否增加了视口大小?Phantomjs:1.9.8,视口大小:1280x720。我会检查错误日志,谢谢!在我的帖子中添加了错误输出,谢谢,可能是我没有看过的页面的重复。链接位于一个框架中,因此您必须先更改为该框架,然后才能单击它。