最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - casperjs clicklabel - Stack Overflow

programmeradmin1浏览0评论

The CasperJS clicklabel allows us to click on DOM element of a kind of tag and inner text.

What if the inner text is wrapped by 2 or more levels? Will it work? For example:

<a href='xxxxxx'><span>my inner text</span></a>

I have tried the below, both seem doesn't work.

clicklabel('my inner text','a')
clicklabel('my inner text','a/span')

The CasperJS clicklabel allows us to click on DOM element of a kind of tag and inner text.

What if the inner text is wrapped by 2 or more levels? Will it work? For example:

<a href='xxxxxx'><span>my inner text</span></a>

I have tried the below, both seem doesn't work.

clicklabel('my inner text','a')
clicklabel('my inner text','a/span')
Share Improve this question edited Aug 9, 2012 at 10:43 vektor 2,9348 gold badges45 silver badges74 bronze badges asked Aug 9, 2012 at 10:29 user1482015user1482015
Add a ment  | 

5 Answers 5

Reset to default 2
clicklabel('my inner text','a span')
this.click('a > span');

This will perform a click event on the first span element inside the 'a' tag.

According to the casperjs docs clickLabel's second parameter is the node name, in your case this is 'span', it doesn't take a selector. You might want to use click instead and use XPath instead of a css selector.

var x = require('casper').selectXPath;
this.click(x('//span[text()="my inner text"]'));

if you are pretty sure that the href attribute is constant just use click with something like : click("a[href='xxxxx']");

else you can try clickLabel('my inner text','span')

if both fail, check that you are not in a page which uses frames, if that's your case, check http://casperjs/api.html#casper.withFrame for how to handle it.

Good luck.

You can directly use :

clickLabel('my inner text','span');

If its not working try waiting for 5 seconds or more after the click , like :

this.wait(5000, function() {
        this.echo("I've waited for 5 seconds.");
    });

waiting for 5 seconds did the trick,as i also faced the same issue.

发布评论

评论列表(0)

  1. 暂无评论