51Testing软件测试论坛

标题: selenium headless无法上传文件 [打印本页]

作者: 测试积点老人    时间: 2021-12-7 09:20
标题: selenium headless无法上传文件
问题遇到的现象和发生背景

selenium 在不加 headless 的时候可正常上传文件,加上 headless 之后无法运行

问题相关代码,请勿粘贴截图

app = pywinauto.Desktop()
dlg = app["打开"]
driver.implicitly_wait(10)

选择文件地址输入框,点击激活

dlg["Toolbar3"].click()
driver.implicitly_wait(10)

键盘输入上传文件的路径

send_keys("D:\附件下载")
sleep(1)

键盘输入回车,打开该路径

send_keys("{VK_RETURN}")
driver.implicitly_wait(10)

选中文件名输入框,输入文件名

dlg["文件名(&N):Edit"].type_keys("配送地址.xlsx")

点击打开
  1. driver.implicitly_wait(10)
  2. dlg["打开(&O)"].click_input()

  3. Traceback (most recent call last):
  4. File "D:\金投云链\venv\lib\site-packages\pywinauto\application.py", line 258, in __resolve_control
  5. criteria)
  6. File "D:\金投云链\venv\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
  7. raise err
  8. pywinauto.timings.TimeoutError

  9. During handling of the above exception, another exception occurred:

  10. Traceback (most recent call last):
  11. File "D:/金投云链/转脚本测试/TEts.py", line 206, in
  12. dlg["Toolbar3"].click()
  13. File "D:\金投云链\venv\lib\site-packages\pywinauto\application.py", line 379, ingetattribute
  14. ctrls = self.__resolve_control(self.criteria)
  15. File "D:\金投云链\venv\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
  16. raise e.original_exception
  17. File "D:\金投云链\venv\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
  18. func_val = func(*args, **kwargs)
  19. File "D:\金投云链\venv\lib\site-packages\pywinauto\application.py", line 203, in __get_ctrl
  20. dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
  21. File "D:\金投云链\venv\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
  22. elements = find_elements(**kwargs)
  23. File "D:\金投云链\venv\lib\site-packages\pywinauto\findwindows.py", line 305, in find_elements
  24. elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems)
  25. File "D:\金投云链\venv\lib\site-packages\pywinauto\findbestmatch.py", line 536, in find_best_control_matches
  26. raise MatchError(items = name_control_map.keys(), tofind = search_text)
  27. pywinauto.findbestmatch.MatchError: Could not find '打开' in 'dict_keys(['QQTXGuiFoundation', 'QQ', 'TXGuiFoundation', '金投云链 – TEts.py PyCharmCXWindow', 'CXWindow', 'XTaskBarBtn', '金投云链 – TEts.py PyCharmXTaskBarBtn', '金投云链 – TEts.py PyCharmShell_TrayWnd', 'Shell_TrayWnd', 'SunAwtWindow', '测试沟通群等3个会话SunAwtWindow', '金投云链 – TEts.py PyCharm', 'SunAwtFrame', '金投云链 – TEts.py PyCharmSunAwtFrame', 'TXGuiFoundation0', 'TXGuiFoundation1', 'TXGuiFoundation2', '测试沟通群等3个会话TXGuiFoundation', '测试沟通群等3个会话', 'Chrome_WidgetWin_1', '(14条消息) Selenium 如何使用webdriver下载文件(chrome浏览器)_breakhl的博客-CSDN博客_webdriver下载文件 - Google Chrome', '(14条消息) Selenium 如何使用webdriver下载文件(chrome浏览器)_breakhl的博客-CSDN博客_webdriver下载文件 - Google ChromeChrome_WidgetWin_1', 'popupshadow', '微信popupshadow', '微信', 'WeChatMainWndForPC', '微信WeChatMainWndForPC', 'DummyDWMListenerWindow', 'EdgeUiInputTopWndClass', 'Internet Explorer_Hidden', 'FLUTTER_RUNNER_WIN32_WINDOW', '小牛 VPN', '小牛 VPNFLUTTER_RUNNER_WIN32_WINDOW', 'Program ManagerProgman', 'Progman', 'Program Manager', '微信SoPY_Status', 'SoPY_Status'])'
复制代码
运行结果及报错内容我的解答思路和尝试过的方法我想要达到的结果

静默上传文件




作者: 海海豚    时间: 2021-12-8 09:35
路径内的\都用\\
作者: qqq911    时间: 2021-12-8 10:27
未找到对应的内容




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2