0

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()
b_rop
  • 1
  • 1
  • If this "alert" appears in the DOM, then simply use WebDriverWait with expected condition visibility_of_element_located and locate the pop-up's selector. If this is a browser alert - then this answer may help you https://stackoverflow.com/questions/60908796/alert-python-selenium-chrome-webdriver-switch-to-alert-doesnt-work – applekate Oct 26 '20 at 16:56
  • Ok I will try this. Thank you for your response. – b_rop Oct 26 '20 at 17:03
  • The code in the post didn't work. The popup I am dealing with is a mic permissions popup. – b_rop Oct 27 '20 at 22:59
  • https://stackoverflow.com/a/55786168/1387701 might help – DMart Oct 28 '20 at 02:17

0 Answers0