【问题标题】:Unable to click on pop up certificate while accessing website using selenium and python使用 selenium 和 python 访问网站时无法单击弹出证书
【发布时间】:2020-04-01 06:55:12
【问题描述】:

我正在尝试使用 selenium 和 python 自动访问网站。该网站有一个证书认证系统,我必须单击“确定”才能进入该网站。我无法点击那里的确定按钮。

我尝试了几种方法,例如 pyrobotautoitpyautogui 等,但我无法单击确定按钮。当我尝试打开这个特定网站时,光标没有移动。

这是一个示例代码:

from selenium import webdriver
import pyautogui

driver = webdriver.Chrome(executable_path="C:\\chromedriver_win32\\chromedriver.exe")
driver.get("URL")
pyautogui.click(x=870, y=450, button='left')

【问题讨论】:

  • 如果没有看到弹出的证书,您可能很难回答。是警报吗?我建议您至少更新问题并添加 HTML(或弹出窗口的屏幕截图)。

标签: python selenium webdriver selenium-chromedriver pywin32


【解决方案1】:

这可以通过线程处理:

import time
import threading
from selenium import webdriver
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")

driver =webdriver.Chrome(executable_path="C:\\chromedriver_win32\\chromedriver.exe")

def manage_os_popup():
   time.sleep(2)
   shell.SendKeys("{ENTER}", 0)
              
my_thread = threading.Thread(target = manage_os_popup)
my_thread.start()

driver.get("URL")
time.sleep(2)

`

【讨论】:

  • 请记住,证书可能是恶意代码,而不是真正的证书。您如何采取措施来检查和防止此类事件发生?
  • 我不知道,但很高兴知道。 :)
  • 您需要能够扫描证书。 GUI 通常具有手动检查证书的选项。该钩子可用于自动检索和检查沙箱区域内的内容。
【解决方案2】:

我不认为 Selenium 可以处理这个问题,使用 Win32com 和 sendkeys(Python/Pywin32 使用来自 Windows Scripting Host 的 WScript)通过快捷方式控制应用程序。例如。

import time

from selenium import webdriver
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")

driver = webdriver.Chrome()
driver.get("URL")
time.sleep(2)
shell.SendKeys("{ENTER}", 0)

Here is a list of WScript-commands:

+----------------+------------------------------+
|      Key       |           Argument           |
+----------------+------------------------------+
| BACKSPACE      | {BACKSPACE}, {BS}, or {BKSP} |
| BREAK          | {BREAK}                      |
| CAPS LOCK      | {CAPSLOCK}                   |
| DEL or DELETE  | {DELETE} or {DEL}            |
| DOWN ARROW     | {DOWN}                       |
| END            | {END}                        |
| ENTER          | {ENTER} or ~                 |
| ESC            | {ESC}                        |
| HELP           | {HELP}                       |
| HOME           | {HOME}                       |
| INS or INSERT  | {INSERT} or {INS}            |
| LEFT ARROW     | {LEFT}                       |
| NUM LOCK       | {NUMLOCK}                    |
| PAGE DOWN      | {PGDN}                       |
| PAGE UP        | {PGUP}                       |
| PRINT SCREEN   | {PRTSC}                      |
| RIGHT ARROW    | {RIGHT}                      |
| SCROLL LOCK    | {SCROLLLOCK}                 |
| TAB            | {TAB}                        |
| UP ARROW       | {UP}                         |
| F1             | {F1}                         |
| F2             | {F2}                         |
| F3             | {F3}                         |
| F4             | {F4}                         |
| F5             | {F5}                         |
| F6             | {F6}                         |
| F7             | {F7}                         |
| F8             | {F8}                         |
| F9             | {F9}                         |
| F10            | {F10}                        |
| F11            | {F11}                        |
| F12            | {F12}                        |
| F13            | {F13}                        |
| F14            | {F14}                        |
| F15            | {F15}                        |
| F16            | {F16}                        |
+----------------+------------------------------+

【讨论】:

  • 不,仍然无法正常工作。它不接受证书。
  • 请立即查看帖子。
  • @AmitDas 当弹出窗口出现时,如果您在键盘上按 Enter - 它接受吗?
猜你喜欢
  • 1970-01-01
  • 2022-12-14
  • 1970-01-01
  • 1970-01-01
  • 2018-03-10
  • 2021-04-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多