Way to Automate file upload with Selenium?

I want to use Selenium to test my Streamlit app. To do this, I need to upload a file to the st.file_uploader. The normal way to do this in Selenium is to send_keys to the element, but this only works if the element is the type, and none of the elements in the file uploader seem to be input type.

Is there any way around this? I can click the “Browse Files” button but then it opens the Windows dialogue which is hard to control.

Never mind, there is actually an input in the file uploader - it’s where you drag a file onto the uploader.

I just had to do this:

    element = driver.find_element(By.XPATH, "//input[@type='file']")

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.

Glad you’ve found the solution and thanks for sharing it with the community!

Best regards,

1 Like