Can't figure it out how upload the file there? It needs to be drag and dropped or just selected via dialog box
We can upload files using Selenium Webdriver. This is achieved by the sendKeys method. We have to first identify the element which performs the file selection by mentioning the file path [to be uploaded].
Uploading files in WebDriver is done by simply using the sendKeys() method on the file-select input field to enter the path to the file to be uploaded. WebDriver cannot automate downloading of files on its own.
We can upload files with Selenium using Python. This can be done with the help of the send_keys method. First, we shall identify the element which does the task of selecting the file path that has to be uploaded. This feature is only applied to elements having the type attribute set to file.
"Looks like you cannot upload files on YouTube using the typical sendkeys method"
4 years later...
@chandan-nayak: You can, here's a python solution to upload a video to YouTube using selenium:
from selenium import webdriver
driver = webdriver.Firefox()
driver.implicitly_wait(5) # Wait up to 5 secs before throwing an error if selenium cannot find the element (!important)
driver.get("https://www.youtube.com/upload")
elem = driver.find_element_by_xpath("//input[@type='file']")
elem.send_keys("C:\\full\\path\to\\video.mp4"); # Window$
#elem.send_keys("/full/path/to/video.mp4"); # Linux
Notes:
1 - Be smart, go slowly but surely;
2 - YouTube max uploads per day is 50, but on the first day is 100;
3 - As of 2019, youtube api is limited to 5 video uploads per day(◔ _◔)
As per the answer here on: stackoverflow Looks like you cannot upload files on YouTube using the typical sendkeys method.
as @Arran said there in the comment section -
Selenium cannot handle file upload dialogs. YouTube uses HTML5 input fields, and Selenium doesn't handle HTML5 elements even in the slightest. As I said, Selenium cannot support this. Selenium won't work here
You shall use the API provided by youtube
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With