簡體   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