Python 类SystemDialog:无法识别我的系统对话框窗口

Python 类SystemDialog:无法识别我的系统对话框窗口,python,selenium-webdriver,Python,Selenium Webdriver,我正试图上传一些文件到一个网站,到目前为止,我已经尝试了我能找到的一切,但没有任何工作。html输入元素不允许我向它发送密钥,所以我找到了这个类来尝试使用它 class SystemDialog: RECURSION_LIMIT = 20 def __init__(self, application_pid, dialog_title=None): self.__path_to_file = None self.__recursions = 0 self.dial

我正试图上传一些文件到一个网站,到目前为止,我已经尝试了我能找到的一切,但没有任何工作。html输入元素不允许我向它发送密钥,所以我找到了这个类来尝试使用它

class SystemDialog:

RECURSION_LIMIT = 20

def __init__(self, application_pid, dialog_title=None):

    self.__path_to_file = None
    self.__recursions = 0

    self.dialog_title = "Open" if dialog_title is None else dialog_title
    self.accept_button = "&SaveButton" if self.dialog_title == "Save As" else "&OpenButton"
    self.decline_button = "&CancelButton"

    app = pywinauto.application.Application()
    app.connect(process=application_pid)
    self.dialog = app.window(title=self.dialog_title)

def __wait_for_dialog(self):
    start = time.time()
    while not self.dialog.exists() and (time.time() - start) <= 10:
        time.sleep(1)
    if not self.dialog.exists():
        raise Exception("System Dialog did not show in 10 seconds")

def input_file_path(self, path_to_file):
    self.__wait_for_dialog()
    self.__path_to_file = path_to_file
    if path_to_file is not None:
        self.dialog.set_focus()
        self.dialog.Edit.type_keys(self.__path_to_file)
    return self

def accept(self):
    if self.__recursions == SystemDialog.RECURSION_LIMIT:
        raise Exception("Not able to accept the System dialog.")

    self.__wait_for_dialog()
    self.dialog.set_focus()
    self.dialog[self.accept_button].click()

    if self.dialog.exists():
        self.__recursions += 1
        if self.__path_to_file is not None:
            return self.input_file_path(self.__path_to_file).accept()  # <--- FYI Recursion
        else:
            raise Exception("Trying to accept dialog without any inputs, not gonna work.")
    self.__recursions = 0

def decline(self):
    if self.__recursions == SystemDialog.RECURSION_LIMIT:
        raise Exception("Not able to decline the System dialog.")

    self.__wait_for_dialog()
    self.dialog.set_focus()
    self.dialog[self.decline_button].click()

    if self.dialog.exists():
        self.__recursions += 1
        return self.decline()  # <--- Recursion
    self.__recursions = 0
我遇到了以下错误:

Traceback (most recent call last):
File "blaineus_v2.py", line 331, in <module>
    main()
  File "blaineus_v2.py", line 64, in main
    uploadPDFs(destination, driver, email, password, projectName)
  File "blaineus_v2.py", line 324, in uploadPDFs
    dialog.input_file_path(path)
  File "blaineus_v2.py", line 91, in input_file_path
    self.__wait_for_dialog()
  File "blaineus_v2.py", line 88, in __wait_for_dialog
    raise Exception("System Dialog did not show in 10 seconds")
Exception: System Dialog did not show in 10 seconds
回溯(最近一次呼叫最后一次):
文件“blaineus_v2.py”,第331行,在
main()
文件“blaineus_v2.py”,第64行,主目录
上传PDF(目的地、驱动程序、电子邮件、密码、项目名称)
上传PDF中的文件“blaineus_v2.py”,第324行
对话框。输入文件路径(路径)
文件“blaineus_v2.py”,第91行,输入文件路径
self.\u等待\u对话框()
文件“blaineus_v2.py”,第88行,在“等待”对话框中
引发异常(“系统对话框在10秒内未显示”)
异常:系统对话框在10秒内未显示
Traceback (most recent call last):
File "blaineus_v2.py", line 331, in <module>
    main()
  File "blaineus_v2.py", line 64, in main
    uploadPDFs(destination, driver, email, password, projectName)
  File "blaineus_v2.py", line 324, in uploadPDFs
    dialog.input_file_path(path)
  File "blaineus_v2.py", line 91, in input_file_path
    self.__wait_for_dialog()
  File "blaineus_v2.py", line 88, in __wait_for_dialog
    raise Exception("System Dialog did not show in 10 seconds")
Exception: System Dialog did not show in 10 seconds