admin管理员组文章数量:1026989
I am making a bot, and this bot is searching constantly but some times when it searches, an alert appears asking the user for access to their location. How do i check if this alert is present or better yet disable it?
So far i have tried to disable stuff through about:config:
var prefs = Components.classes["@mozilla/preferences-
service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("network.cookie.cookieBehavior", 4);
prefs.setBoolPref("privacy.donottrackheader.enabled", true);
prefs.setIntPref("permissions.default.geo", 2);
But alerts still pop up. I also tried making a new firefox profile with pre installed add-ons just to block dialog boxes and pop ups, but it still gives me dialog boxes.
I really am stumped this time. If you know how i can check if a page is alerting something with JS or Selenium python then please tell me cause at this point, that would help me a lot. If you know how to disable javascript alerts then that would be awesome.
I am making a bot, and this bot is searching constantly but some times when it searches, an alert appears asking the user for access to their location. How do i check if this alert is present or better yet disable it?
So far i have tried to disable stuff through about:config:
var prefs = Components.classes["@mozilla/preferences-
service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("network.cookie.cookieBehavior", 4);
prefs.setBoolPref("privacy.donottrackheader.enabled", true);
prefs.setIntPref("permissions.default.geo", 2);
But alerts still pop up. I also tried making a new firefox profile with pre installed add-ons just to block dialog boxes and pop ups, but it still gives me dialog boxes.
I really am stumped this time. If you know how i can check if a page is alerting something with JS or Selenium python then please tell me cause at this point, that would help me a lot. If you know how to disable javascript alerts then that would be awesome.
Share Improve this question asked Mar 23, 2019 at 17:46 SuperSimplePimpleDimpleSuperSimplePimpleDimple 5661 gold badge4 silver badges20 bronze badges 4- This might help, possible duplicate stackoverflow./questions/38767551/… – David Silveiro Commented Mar 23, 2019 at 19:06
- @David it is actually an alert not a pop-up. If it was a pop up my add-ons would have blocked it. – SuperSimplePimpleDimple Commented Mar 23, 2019 at 19:07
- Are you using chrome and firefox? – Pritam Maske Commented Mar 23, 2019 at 19:46
- @PritamMaske Firefox. – SuperSimplePimpleDimple Commented Mar 23, 2019 at 23:51
3 Answers
Reset to default 3You can disable alerts with:
window.alert = () => false
from python that's:
driver.execute_script("window.alert = () => false")
Use :
prefs.setIntPref("permissions.default.desktop-notification", 1);
Assume one is present on the exception of a non located element within a try/catch block, then try to use
driver.switchTo().alert().dismiss();
to proceed with the entended behavior :)
I am making a bot, and this bot is searching constantly but some times when it searches, an alert appears asking the user for access to their location. How do i check if this alert is present or better yet disable it?
So far i have tried to disable stuff through about:config:
var prefs = Components.classes["@mozilla/preferences-
service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("network.cookie.cookieBehavior", 4);
prefs.setBoolPref("privacy.donottrackheader.enabled", true);
prefs.setIntPref("permissions.default.geo", 2);
But alerts still pop up. I also tried making a new firefox profile with pre installed add-ons just to block dialog boxes and pop ups, but it still gives me dialog boxes.
I really am stumped this time. If you know how i can check if a page is alerting something with JS or Selenium python then please tell me cause at this point, that would help me a lot. If you know how to disable javascript alerts then that would be awesome.
I am making a bot, and this bot is searching constantly but some times when it searches, an alert appears asking the user for access to their location. How do i check if this alert is present or better yet disable it?
So far i have tried to disable stuff through about:config:
var prefs = Components.classes["@mozilla/preferences-
service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setIntPref("network.cookie.cookieBehavior", 4);
prefs.setBoolPref("privacy.donottrackheader.enabled", true);
prefs.setIntPref("permissions.default.geo", 2);
But alerts still pop up. I also tried making a new firefox profile with pre installed add-ons just to block dialog boxes and pop ups, but it still gives me dialog boxes.
I really am stumped this time. If you know how i can check if a page is alerting something with JS or Selenium python then please tell me cause at this point, that would help me a lot. If you know how to disable javascript alerts then that would be awesome.
Share Improve this question asked Mar 23, 2019 at 17:46 SuperSimplePimpleDimpleSuperSimplePimpleDimple 5661 gold badge4 silver badges20 bronze badges 4- This might help, possible duplicate stackoverflow./questions/38767551/… – David Silveiro Commented Mar 23, 2019 at 19:06
- @David it is actually an alert not a pop-up. If it was a pop up my add-ons would have blocked it. – SuperSimplePimpleDimple Commented Mar 23, 2019 at 19:07
- Are you using chrome and firefox? – Pritam Maske Commented Mar 23, 2019 at 19:46
- @PritamMaske Firefox. – SuperSimplePimpleDimple Commented Mar 23, 2019 at 23:51
3 Answers
Reset to default 3You can disable alerts with:
window.alert = () => false
from python that's:
driver.execute_script("window.alert = () => false")
Use :
prefs.setIntPref("permissions.default.desktop-notification", 1);
Assume one is present on the exception of a non located element within a try/catch block, then try to use
driver.switchTo().alert().dismiss();
to proceed with the entended behavior :)
本文标签: pythonHow to check if an alert is present on a page with JavaScript or SeleniumStack Overflow
版权声明:本文标题:python - How to check if an alert is present on a page with JavaScript or Selenium - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745659888a2161824.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论