单击该元素,但不会相应地重新加载Page [英] The element is clicked, but Page is not reloaded accordingly

查看:118
本文介绍了单击该元素,但不会相应地重新加载Page的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用幻影JS,尝试单击<li>元素(target_element)并呈现在其后加载的页面.单击元素成功.但是,在渲染时,刷新的页面在输出中看不到.我给了足够的等待项目.代码是:

Using phantom JS, I am trying to click a <li> element(target_element) and render the page which loads after it. The element is clicked successfully. But, on rendering, the refreshed page is not seen in the output. I have given enough wait item. The code is:

page.open(address, function (status) {
    if (status !== 'success') {
        console.log('Unable to load the address!');
        phantom.exit();
    } else {
        window.setTimeout(function () {
            page.evaluate(function() {
                document.getElementById('custom_filters').style.visibility = "hidden";
                var a = document.getElementById('target_element');
                var e = document.createEvent('MouseEvents');
                e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
                console.log(a.dispatchEvent(e));
                waitforload = true;
            });
            page.render(output);
            phantom.exit();
        }, waitTime);
    }
});

这是否意味着该事件尚未触发JS函数,或者我在这里做错了什么?

Does this mean The event has not triggered the JS function or am I doing anything wrong here?

推荐答案

不,您在单击和渲染之间没有任何等待时间. setTimeout只需要在需要延迟的呼叫周围.

No, you didn't have any wait time between click and render. The setTimeout needs to be only around the calls that need to be delayed.

page.evaluate(function() {
    document.getElementById('custom_filters').style.visibility = "hidden";
    var a = document.getElementById('target_element');
    var e = document.createEvent('MouseEvents');
    e.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
    console.log(a.dispatchEvent(e));
    waitforload = true;
});
window.setTimeout(function () {
    page.render(output);
    phantom.exit();
}, waitTime);

这篇关于单击该元素,但不会相应地重新加载Page的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆