Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How upload file to youtube via selenium webdriver python?

Can't figure it out how upload the file there? It needs to be drag and dropped or just selected via dialog box

like image 268
MadRabbit Avatar asked Jun 27 '15 08:06

MadRabbit


People also ask

Can we upload file using Selenium WebDriver?

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].

How do you do file upload in WebDriver?

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.

How does Python handle file upload window in Selenium?

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.


2 Answers

"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(◔ _◔)

like image 175
Pedro Lobito Avatar answered Nov 01 '22 15:11

Pedro Lobito


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

like image 29
Chandan Nayak Avatar answered Nov 01 '22 16:11

Chandan Nayak