如何点击<a> tag in phantomjs 2.0.0?

时间:2015-09-16 07:49:19

标签: javascript click phantomjs

There is a onclick function tied up with this tag. I need to trigger this onclick function, so I used

page.sendEvent('click', element.offsetLeft, element.offsetTop, 'left');

But it seems not working. How to make a click on tag? Thanks for any help!

1 个答案:

答案 0 :(得分:0)

您可以通过

包含jquery
page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', callback_function);

更多信息:http://phantomjs.org/api/webpage/method/include-js.html

然后使用jQuery并从回调函数

执行
page.evaluate(function(){
    $('#mylink').trigger('click');
});