0

I'm at the final stage of this small project using Python/Selenium to navigate through a platform I use to bulk upload csv files. enter image description here

I can't seem to find a way to specify the path/file location to then select (open) the file to upload to the website. I am trying to use the code below:

filepath = filedialog.askopenfilenames(initialdir="C:\\Users\\MyFolder")
subprocess.Popen('explorer "C:\my_file.csv"')

How do I select the correct file to then click 'open' after navigating through the website? Any help would be greatly appreciated. Thanks so much in advance.

mexicanRmy
  • 69
  • 7

1 Answers1

0

So I found a work around to this issue. I used the below code to locate the input element instead:

s = driver.find_element(By.XPATH, "//input[@type='file']")
#file path specified with send_keys
s.send_keys(r"C:\Users\MyFolder\my_file.csv")

Here are some resources I used: Selenium Documentation

Upload Files With Python

Handle Windows File Upload Using Selenium - Java

Thanks to anyone who wanted to help!

mexicanRmy
  • 69
  • 7