PhantomJS; click an element

前端 未结 11 987
借酒劲吻你
借酒劲吻你 2020-11-21 23:53

How do I click an element in PhantomJS?

page.evaluate(function() {
    document.getElementById(\'idButtonSpan\').click();  
});

This gives

11条回答
  •  滥情空心
    2020-11-22 00:21

    Hope the following method will be useful. It worked for me in version 1.9

    page.evaluate(function(){
        var a = document.getElementById("spr-sign-in-btn-standard");
        var e = document.createEvent('MouseEvents');
        e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        a.dispatchEvent(e);
        waitforload = true;
    });
    

    This worked for me. Hope this will be useful for others also

提交回复
热议问题