1

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.sstatic.net/EHktU.png

1 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

3 Comments

thanks! it didn't gave me any error but the windows files never opened and the file hasn't been uploaded!
I resolve it this way selec = driver.find_element_by_xpath('//*[@name="IMPORT_FILE"]') time.sleep(2) selec.send_keys('C:/ETL/Contact/datos.csv') pyautogui.press('enter')
Oh..Sorry..i didn't see your comment before. Glad it worked out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.