单击网页“选择文件”时,Windows文件不会打开。硒Python

2024-09-24 22:26:35 发布

您现在位置: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


Tags: 文件name密码bywindowsdriver错误页面
1条回答
网友
1楼 · 发布于 2024-09-24 22:26:35

通过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')

相关问题 更多 >