2

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.org/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.

3 Answers3

3

You can disable alerts with:

window.alert = () => false

from python that's:

driver.execute_script("window.alert = () => false")
pguardiario
  • 51,516
  • 17
  • 106
  • 147
2

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

David S
  • 1,406
  • 1
  • 13
  • 21
2

Use :

prefs.setIntPref("permissions.default.desktop-notification",  1);
Pritam Maske
  • 2,472
  • 2
  • 18
  • 28