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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744703824a4588934.html
评论列表(0条)