Search code examples
pythonseleniumgoogle-chromecertificate

How to handle certificate OS pop up in Selenium python? I tried pyAutoGUI, but it didn't work


I work with Selenium on python to navigate at Google-Chrome. At some point in my application SSL certificate pops up (It suppose to be here, I have a legit certificate, I just need to press 'Ok'). If I understand it right, it is not a browser's popup, but an OS popup. Thus, selenium can't handle it. To solve the problem I tried pyautogui that is supposed to handle OS popups.

from selenium import webdriver
import pyautogui

driver = webdriver.Chrome() 
driver.get(url)  # fetching the page
res = driver.\ 
    execute_script("return document.documentElement.outerHTML")

At this point Certificate Window pops up. I try to click on it with pyautogui:

pyautogui.moveTo(100, 100, duration = 0.5) 

But the problem is that when the certificate popup window appears, the scrip stops and pyautogui can't move the mouse to click on the certification. When I click manually 'Ok' on the window, pyautogui starts to work. But I need it to click 'Ok' automatically. Does anyone know how to handle this script freeze? Thanks!


Solution

  • Managed to solve it with two separated threads (thanks @wizzwizz4 for the idea):

    from selenium import webdriver
    import pyautogui
    
    def manage_os_popup():
        time.sleep(5)
        pyautogui.moveTo(100, 100, duration = 0.5)
        time.sleep(1)
        pyautogui.click()
    
    my_thread = threading.Thread(target = manage_os_popup)
    my_thread.start()
    
    driver = webdriver.Chrome() 
    driver.get(url)
    res = driver.\ 
        execute_script("return document.documentElement.outerHTML")