0

I have currently been using selenium perfectly well in python to this point, but I am not sure how to accept the popup message that the site is creating. enter image description here

I have already tried using

alert_obj = driver.switch_to.alert
alert_obj.accept()

, but I just get a error from my python output saying that the alert was not found:

Traceback (most recent call last):
  File "C:\Users\KDJ\Documents\GameJoiner\Main.py", line 42, in <module>
    alert_obj = driver.switch_to.alert
  File "C:\Users\KDJ\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\switch_to.py", line 55, in alert
    alert.text
  File "C:\Users\KDJ\AppData\Local\Programs\Python\Python38\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\KDJ\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\KDJ\AppData\Local\Programs\Python\Python38\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

I'm using the chrome web driver. Anyone know what I should do to make it work?

Thanks!

chrome_options = webdriver.ChromeOptions()

userProfile = "C:\\Users\\KDJ\\Documents\\GameJoiner\\User Data\\Default";

chrome_options.add_argument('user-data-dir='+userProfile)

driver = webdriver.Chrome('C:\\Users\KDJ\Documents\GameJoiner\chromedriver.exe', options=chrome_options)
KDJ
  • 105
  • 1
  • 2
  • 9

1 Answers1

1

I'll write it in Java:

boolean b = false;

while(!b) {

  try {

    driver.switchto().alert();

    b = true;

  } catch(Exception e) {}

}

You can use Try Except and bool() function in Python.

  • 1
    Could I find it this way though? I'm really not sure if this would work since it's a pop up being produced by the browser, that is requested by the browser. It's not really in the HTML itself. – KDJ Sep 22 '20 at 14:09
  • I hit the edit button by accident. I didn't change anything. – KDJ Sep 22 '20 at 14:51
  • I mentioned that I already tried driver.switch_to.alert in the original post, and I still have the problem. – KDJ Sep 22 '20 at 15:17
  • I tried using a user profile that includes the always open option checked, but I had no success. It still prompted me to click the check. I attached the code I am using to the OP. – KDJ Sep 22 '20 at 21:00
  • 1
    I ended up solving the issue! Thank you for your help! – KDJ Sep 22 '20 at 23:01
  • Hi @KDJ, can you explain how did you solve the issue? – Syed Adnan Haider Mar 27 '21 at 05:29