如何结束 PhantomJS 中无穷无尽的警报消息流
How to end an endless stream of alert messages in PhantomJS
如何在 PhantomJS 中关闭无限警报?
一个网站有无尽的警报
我用过
page.onAlert = function(msg) {
console.log('ALERT: ' + msg);
};
查看网站是否有警报
但是这种方法你永远不会停止,因为那是一个无休止的警报
您不必打印您正在访问的页面向您发送的所有提醒。只需删除处理程序即可使它们静音:
page.onAlert = function(msg) {
console.log('ALERT: ' + msg);
page.onAlert = function(){};
};
这仅打印第一个警报。您可以通过添加计数警报或类似的东西使它更复杂。
对每个稍后会有提醒的重新加载页面尝试此操作。
driver.execute_script("window.confirm = function(){return true;}");
查看更多参考资料here。
如何在 PhantomJS 中关闭无限警报?
一个网站有无尽的警报
我用过
page.onAlert = function(msg) {
console.log('ALERT: ' + msg);
};
查看网站是否有警报
但是这种方法你永远不会停止,因为那是一个无休止的警报
您不必打印您正在访问的页面向您发送的所有提醒。只需删除处理程序即可使它们静音:
page.onAlert = function(msg) {
console.log('ALERT: ' + msg);
page.onAlert = function(){};
};
这仅打印第一个警报。您可以通过添加计数警报或类似的东西使它更复杂。
对每个稍后会有提醒的重新加载页面尝试此操作。
driver.execute_script("window.confirm = function(){return true;}");
查看更多参考资料here。