Casperjs Selector [CasperError]

1

I want to test using CasperJS . I want it to click the login button.

I have the following menu:

<ul id="menu-top">
<li class="0 first"><a title="" href="/empresa">Empresa</a></li>
<li class="1"><a title="" href="/plano-de-negocio">Plano de Negócio</a></li>
<li class="2"><a title="" href="/produtos">Produtos</a></li>
<li class="3"><a title="" href="/contato">Contato</a></li>
<li class="4 last"><a title="" href="login.php">Área restrita</a></li>
</ul>

To click, I used the following code:

var casper = require('casper').create({
    verbose: true,
    logLevel: "debug"
});
casper.start('http://localhost/teste');

casper.then(function(){
    this.click('.4.last>a');
});

casper.run();

But I get the following error:

  

[error] [remote] findAll (): invalid selector provided ".4.last>": Error: SYNTAX_ERR: DOM Exception 12

     

CasperError: Can not dispatch mousedown event on nonexistent selector: .4.last> a

I'm using the firepath to fetch the button's css path (.4.last> a)

    
asked by anonymous 16.04.2014 / 21:23

2 answers

2

I was able to solve my problem by indicating that I would insert an XPath. So:

var x = require('casper').selectXPath;

casper.then(function(){
    this.click(x(".//*[@id='menu-top']/li[5]/a"));  
});
    
16.04.2014 / 22:02
1

Just to complement ... Another simple way is to use clickLabel() :

this.clickLabel('Área restrita', 'a');

Or, adjust CSS Path to:

'#menu-top > li:nth-child(5) > a'

or a third possibility:

'a[href="login.php"]'
    
25.07.2015 / 06:16