admin管理员组文章数量:1391929
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
5 Answers
Reset to default 2clicklabel('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.
本文标签: javascriptcasperjs clicklabelStack Overflow
版权声明:本文标题:javascript - casperjs clicklabel - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744703821a2620720.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论