I am trying to build a bot and that needs to be able to interact with permission boxes. This bot is supposed to click accept/dismiss depending on what the user input; however, every time I attempt to interact with the permissions popup that appears in the html file I get the error mentioned below. I have lightly looked into the Alert object, and I have tried driver.switch_to_alert(), but, I find that that has been deprecated. I running the latest version of python, and the the latest version of selenium, along with the latest version of the chrome driver. The error message below, is the same message I get for all methods I have attempted to use to solve this problem.
driver.switch_to_alert()
Traceback (most recent call last):
File "C:/Users/micha/PycharmProjects/botty/alert_testing.py", line 9, in <module>
driver.switch_to_alert()
File "C:\Users\micha\.virtualenvs\botty-KuDX6gMP\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 803, in switch_to_alert
return self._switch_to.alert
File "C:\Users\micha\.virtualenvs\botty-KuDX6gMP\lib\site-packages\selenium\webdriver\remote\switch_to.py", line 55, in alert
alert.text
File "C:\Users\micha\.virtualenvs\botty-KuDX6gMP\lib\site-packages\selenium\webdriver\common\alert.py", line 67, in text
return self.driver.execute(Command.W3C_GET_ALERT_TEXT)["value"]
File "C:\Users\micha\.virtualenvs\botty-KuDX6gMP\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\micha\.virtualenvs\botty-KuDX6gMP\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoAlertPresentException: Message: no such alert
(Session info: chrome=86.0.4240.111)
Process finished with exit code 1
My code:
from selenium.webdriver import Chrome
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.common.alert import Command
from time import sleep
driver = Chrome()
driver.get('file:///C:/Users/micha/Scripts/web%20design/javaScriptTesting/jscriptTesting.html')
sleep(3)
al = driver.switch_to.alert
al.accept()
input()