Problem Using XPath Selectors

747 views
Skip to first unread message

Or Perlman

unread,
May 22, 2013, 9:27:10 AM5/22/13
to casp...@googlegroups.com
I have been trying for the last couple of hours to use an xpath selector in casperJS.
Unfortunately, none of the selectors I write (even something such as: '//*[@id="enabled_1_0_BONUSFF1E"]') work.
I receive an error saying: FAIL the element exists.

I tried using the example in the casperJS site:

and also changing the user-agent:

but nothing seems to work.

I am using casperJS 1.0.2 with phantomJS 1.8.1.
Do anyone have any suggestion how to fix this problem?


Ankita

unread,
May 22, 2013, 6:48:23 PM5/22/13
to casp...@googlegroups.com
Hi 

I tried something like this on casperJS with coffee script which did work for me..






--
CasperJS homepage & documentation: http://casperjs.org/
CasperJS @github: https://github.com/n1k0/casperjs
 
You received this message because you are subscribed to the Google Groups "casperjs" group.
Visit this group at http://groups.google.com/group/casperjs?hl=en.
---
You received this message because you are subscribed to the Google Groups "CasperJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to casperjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Ankita

unread,
May 22, 2013, 6:49:21 PM5/22/13
to casp...@googlegroups.com
This might work for you

this.click(
      '{
        type: 'xpath',
        path: '//[@id="enabled_1_0_BONUSFF1E"]') '
      }');

Evan Rowley

unread,
May 28, 2013, 2:18:12 PM5/28/13
to casp...@googlegroups.com
I've just spent an hour working out some XPath queries. Not sure if this will fix yours, but you could rewrite it as so and see what happens:

 '//*[contains(@id,"enabled_1_0_BONUSFF1E")]'

I don't know why replacing the equals operand should do anything, but my query evolved this way and it works:

'//*[contains(@class,"inputtext") and contains(@type,"text") and contains(@name,"email")]'

Evan Rowley

unread,
May 28, 2013, 2:21:55 PM5/28/13
to casp...@googlegroups.com
And one more thing. If you're running some kind of *nix then you could use grep and Casper#debugHTML() to see if the correct HTML elements are actually coming though.

Place this.debugHTML(); somewhere in your .js, like:

casper.then(function() {
    this.test.assertExists({
        type: 'xpath',
        path: '//*[contains(@class,"inputtext") and contains(@type,"text") and contains(@name,"email")]'
    }, this.debugHTML());
});


and then at the console when you run it, pipe the output to grep like so:

casperjs myscript.js | grep enabled_1_0_BONUSFF1E
Reply all
Reply to author
Forward
0 new messages