I'm trying to use selenium to download files from a webpage that requires a certificate. I have multiple certificates on my computer so every time when there is a pop-up window, I need to choose the right certificate to access the content of that webpage. For now, when the computer is not locked, I can run selenium and perform all these tasks automatically without issues. But after running my code script and if I lock my screen, the following errors encounter:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:Userslmsunanaconda3libhreading.py", line 926, in _bootstrap_inner
self.run()
File "C:Userslmsunanaconda3libhreading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "C:/Users/lmsun/Desktop/Five Dimensions Energy/Liming/ERCOT_Download/ERCOT_Download.py", line 52, in threaded_function2
pyautogui.press('down')
File "C:Userslmsunanaconda3libsite-packagespyautogui\__init__.py", line 1174, in press
failSafeCheck()
File "C:Userslmsunanaconda3libsite-packagespyautogui\__init__.py", line 1257, in failSafeCheck
raise FailSafeException('PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen. To disable this fail-safe, set pyautogui.FAILSAFE to False. DISABLING FAIL-SAFE IS NOT RECOMMENDED.')
pyautogui.FailSafeException: PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen. To disable this fail-safe, set pyautogui.FAILSAFE to False. DISABLING FAIL-SAFE IS NOT RECOMMENDED.
I can make this error go away by freezing my mouse. but it seems selenium cannot deal with the certificate pop-up window anymore after I lock my screen. Does anyone know if there is a solution? Thank you.
```
def threaded_function(url, browser):
# Calls the website
browser.get(url)
return
def threaded_function2():
global cert_num
# give enough time so that the pop will appear before the press
time.sleep(10) # this needs to be hardcoded, if pass in as a parameter, thread error occurs
# choose the right certification
for i in range(cert_num):
pyautogui.press('down')
time.sleep(2)
pyautogui.press('enter')
return
while ind2 < 5:
try:
if ind2 != 0:
print(f"Retrying open {folder_name_2}, {ind2 + 1}")
browser = webdriver.Chrome(driver_directory)
# Check version of msedgedriver.exe and Edge
str1 = browser.capabilities['browserVersion']
str2 = browser.capabilities['chrome']['chromedriverVersion'].split(' ')[0]
if str1[0:2] != str2[0:2]:
print("please download correct msedgedriver version")
return
print("Selenium operating starts...")
cert_num = int(input_df[cert_end + '''].values.tolist()[0]) - 1
cert_dir = input_df[cert_end + '''].values.tolist()[1]
thread2 = threading.Thread(target=threaded_function2)
thread2.start()
thread = threading.Thread(target=threaded_function(url, browser))
thread.start()
thread.join()
thread2.join()
if ind2 != 0:
print(f'The issue is solved, reopen window for {folder_name_2} successfully.')
ind2 = 5
```
question from:
https://stackoverflow.com/questions/65944797/how-to-use-selenium-to-download-from-a-web-with-certificates-while-locking-the-s 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…