How to allow selenium/chrome driver alerts on a droplet

Hello all, I was attempting to automate several processes on a droplet, and yet, for some reason have been running into an issue with the following bit of python code: from selenium import webdriver from import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.action_chains import ActionChains from import Options from import WebDriverWait import time options = Options() from pyvirtualdisplay import Display display = Display(visible=0, size = [1000,1000]) display.start() options.add_argument(‘–no-sandbox’) WD = webdriver.Chrome(options=options) print(“Webdriver and display loaded”) def loginSC(url,driver, iden, password):
result = None driver.get (url) while result is None: try: driver.find_element(By.ID,“ContentPlaceHolder1_txtUserName”).send_keys(iden) driver.find_element (By.ID,“ContentPlaceHolder1_txtPassword”).send_keys(password) driver.find_element(By.ID,“ContentPlaceHolder1_btnLogin”).click() result=1 except: time.sleep(5) print(“Trying again…1”) print(“Page 1 Loaded!”) result = None print(driver.current_url) while result is None: driver.find_element(By.ID,“ContentPlaceHolder1_chkCampus_1”).click() driver.find_element(By.ID,“ContentPlaceHolder1_chkSymptoms_8”).click() driver.find_element(By.ID,“ContentPlaceHolder1_chkPolicyConfirmation”).click() driver.find_element(By.ID,“ContentPlaceHolder1_btnSubmit”).click() time.sleep(5) driver.switch_to.alert.accept(); result=1

While this runs fine on my own PC, it gives the following error when run on my droplet: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“[id=“alert1”]”} (Session info: chrome=98.0.4758.80)

I can’t seem to find a way to make the driver “see” the alert, and I suspect it has something to do with the mandatory no-sandbox mode. How can I circumvent this?

Submit an answer
Answer a question...

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer