单击没有ID的链接或带有casperJS的类

时间:2015-12-18 18:40:19

标签: phantomjs casperjs

我试图获取此页面左侧菜单上的链接列表:http://www.hpenterprisesecurity.com/vulncat

我要做的第一件事就是点击"展开全部"链接(在左上角),以便列表扩展。

我尝试过多种方式以不同的方式使用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;

phantomjs: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.

0 个答案:

没有答案
相关问题