如何处理在 Selenium python 中弹出的证书 OS?我试过 pyAutoGUI,但没有用
How to handle certificate OS pop up in Selenium python? I tried pyAutoGUI, but it didn't work
我在 python 上使用 Selenium 在 Google-Chrome 导航。
在我的应用程序中的某个时候弹出 SSL 证书(它应该在这里,我有一个合法证书,我只需要按 'Ok')。如果我没理解错的话,那不是浏览器弹窗,而是OS弹窗。因此,硒无法处理它。为了解决这个问题,我尝试了应该处理 OS 弹出窗口的 pyautogui。
from selenium import webdriver
import pyautogui
driver = webdriver.Chrome()
driver.get(url) # fetching the page
res = driver.\
execute_script("return document.documentElement.outerHTML")
此时证书Window弹出。我尝试用pyautogui点击它:
pyautogui.moveTo(100, 100, duration = 0.5)
但问题是当证书弹窗window出现时,脚本停止,pyautogui无法移动鼠标点击证书。当我在 window 上手动单击 'Ok' 时,pyautogui 开始工作。但我需要它自动点击 'Ok' 。
有谁知道如何处理这个脚本冻结?
谢谢!
设法用两个单独的线程解决它(感谢@wizzwizz4 的想法):
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")
我在 python 上使用 Selenium 在 Google-Chrome 导航。 在我的应用程序中的某个时候弹出 SSL 证书(它应该在这里,我有一个合法证书,我只需要按 'Ok')。如果我没理解错的话,那不是浏览器弹窗,而是OS弹窗。因此,硒无法处理它。为了解决这个问题,我尝试了应该处理 OS 弹出窗口的 pyautogui。
from selenium import webdriver
import pyautogui
driver = webdriver.Chrome()
driver.get(url) # fetching the page
res = driver.\
execute_script("return document.documentElement.outerHTML")
此时证书Window弹出。我尝试用pyautogui点击它:
pyautogui.moveTo(100, 100, duration = 0.5)
但问题是当证书弹窗window出现时,脚本停止,pyautogui无法移动鼠标点击证书。当我在 window 上手动单击 'Ok' 时,pyautogui 开始工作。但我需要它自动点击 'Ok' 。 有谁知道如何处理这个脚本冻结? 谢谢!
设法用两个单独的线程解决它(感谢@wizzwizz4 的想法):
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")