5

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

MadRabbit
  • 2,460
  • 2
  • 17
  • 18
  • have you seen [this](http://stackoverflow.com/questions/8428102/upload-file-with-selenium-in-python), [this](http://stackoverflow.com/questions/18823139/selenium-webdriver-upload-file) and [this](http://stackoverflow.com/questions/8665072/how-to-upload-file-picture-with-selenium-python) ? – Pynchia Jun 27 '15 at 09:00
  • Yeah, I've seen and tried alf of those but it doesn't seem to work in case of youtube. – MadRabbit Jun 27 '15 at 11:43

4 Answers4

5

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

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
  • Your answer is still working well in window10. currently at most 15 videos could be uploaded at one time, any idea how to pass the argument to send key function? `Elem.send_keys("C:\\first.mp4","C:\\second.mp4")` this does not work – Luk Aron Jun 15 '20 at 13:13
  • @LukAron I'll give it a try asa I've some free time and update the answer if I I find the solution. – Pedro Lobito Jun 17 '20 at 02:31
  • 1
    I found it, simply separate the path by a "," – Luk Aron Jun 17 '20 at 14:14
  • Great! can you please provide an example as comment so I can update the answer? – Pedro Lobito Jun 17 '20 at 15:36
  • seems that I couldn't do so anymore. Maximum one path per time. – Luk Aron Jul 12 '20 at 09:59
  • @LukAron sniff the request using the browser developer console network tab and emulate it using selenium. I've no time to test it now, but if you can do it on the browser, you certainly can do it using selenium. – Pedro Lobito Jul 12 '20 at 17:30
2

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

Community
  • 1
  • 1
Chandan Nayak
  • 10,117
  • 5
  • 26
  • 36
0

5 years later...

I run into the same issue and found youtube-uploader-selenium package.

As of 2019, youtube api is limited to 5 video uploads per day(◔ _◔)

The description says

Instead, this script is only restricted by a daily upload limit for a channel on YouTube: 100 videos is the limit in the first 24 hours, then drops to 50 every 24 hours after that.

0

you may need this give it a shot ytb_up based selenium

https://github.com/wanghaisheng/ytb-up features YOU MAY NEED

  1. proxy support

auto detect whether need a proxy 2. cookie support

for those multiple channels under same google account 3. schedule time publish

you can explictly specify a date and time for each video or you can set publish policy and daily public count,for example,daily count is 4,you got 5 videos,then first 4 will be published 1 day after the upload date ,the other 1 will be 2 days after the upload date 4. fix google account verify

edwin_uestc
  • 169
  • 2
  • 11