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 :)