简体   繁体   中英

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

So, I need to upload a file to a page. When i click on the input button (and it clicks without error), windows files to search for the file i need, does not open. Here its my code snip. and what i need to be open at click

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

[![windows files][1]][1]

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

Install pyautogui via pip and do this.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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