I have a script that automates some things on Chrome with Selenium, which works like a charm. The only problem is that at some point I want to upload a file from my computer to the webpage. For this purpose, a Windows system popup will show in which I need to navigate to the correct file, followed by clicking 'Open' to upload the file.
It seems that Selenium is not able to handle this, but what is able to handle this then? I'm also not sure how to focus the script to the popup (or if that is even needed).
I hope someone can help.
CodePudding user response:
To upload file with Selenium:
1 Find the input element with type=file.
2 Call send-keys selenium command and send the file absolute path text to the input-file element.
file_input = driver.find_element_by_xpath("//input[@type='file']")
file_input.send_keys("D:\\Documents\\user-logo.jpg")
No additional clicks required.
