繁体   English   中英

Windows 在网页中单击“选择文件”时文件无法打开。 Selenium Python

[英]Windows Files does not open when click in webpage “Select file”. Selenium Python

所以,我需要将文件上传到页面。 当我点击输入按钮(它点击没有错误)时,windows 文件搜索我需要的文件,没有打开。 这是我的代码片段。 以及我需要在点击时打开的内容

#IMPORTAR DATOS
selec = driver.find_element_by_xpath('//*[@name="IMPORT_FILE"]')
driver.execute_script("arguments[0].click();", selec)
time.sleep(2)

[![Windows 文件][1]][1]

谢谢:[1]: https://i.stack.imgur.com/EHktU.png

通过pip安装pyautogui并执行此操作。

import pyautogui
... # set the webdriver etc.
...
...
element_present = EC.presence_of_element_located((By.XPATH, "//button[@title='Open file selector']"))  # Example xpath

WebDriverWait(self.driver, 10).until(element_present).click() # This opens the windows file selector

pyautogui.write('C:/path_to_file') 
pyautogui.press('enter')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM