Reputation: 306
How to upload file using python selenium-webdriver when there is no input type but instead it has a button type in HTML?
I'm trying to upload a file to a webpage using Selenium but the HTML type is a button not an Input file.
Below is the HTML Code
Button looks like this
My code
browser.find_element_by_class_name("ng-scope").send_keys('C:\\Users\\Desktop\\test.png')
But after I run the code the file is not uploaded.
Please advise on where i'm going wrong?
Thanks in advance -M
Upvotes: 2
Views: 6303
Reputation: 12255
There is a hidden input with type=file
. To upload file using Selenium yo have to send keys to input[type=file]
:
browser.find_element_by_css_selector(".file-upload-input input[type=file]").send_keys('C:\\Users\\Desktop\\test.png')
Use WebDriverWait
to wait element to be present in the DOM:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# ...
wait = WebDriverWait(driver, 5)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".file-upload-input input[type=file]"))).send_keys('C:\\Users\\Desktop\\test.png')
Upvotes: 5