1

I am trying to make a YouTube video uploader to upload a video with a single click. So far I am managing to get to the http://www.youtube.com/upload page, but I can not find a way to use the button to upload my video.

After a little research I have found out that the proper way to upload a file is uploadVid.SendKeys("C:\\video.flv");. So far I am at this point:

    //  IWebElement uploadVid = driver.FindElement(By.Id("start-upload-button-single"));
   //   IWebElement uploadVid = driver.FindElement(By.XPath("//*[@id=\"upload-prompt-box\"]/div[1]"));
  //    IWebElement uploadVid = driver.FindElement(By.XPath("//*[@id=\"start-upload-button-single\"]"));
        IWebElement uploadVid = driver.FindElement(By.ClassName("upload-drag-drop-description"));
        uploadVid.SendKeys("C:\\video.flv"); 

The lines I have commented out are what I have tried so far without any success. I keep getting error element not found .

I use C# Selenium WebDriver in VS2013, WPF.

12
  • 4
    This is unnecessary. YouTube has an API to upload videos: developers.google.com/youtube/v3/code_samples/… ...you don't need Selenium at all. Commented Mar 24, 2014 at 22:49
  • @Arran, I do not want to use the API. Commented Mar 25, 2014 at 7:04
  • Why do you not want to use the API? It would be far simpler, less error-prone and more efficient to use the API rather than attempting to use Selenium for this purpose. Selenium is the fallback solution for when an API is not available or not adequate. Commented Mar 25, 2014 at 15:22
  • 1
    @AntonioPetrov, as I said, 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. Commented Mar 26, 2014 at 22:49
  • 1
    @Arran your comment has unfortunately not aged well as we in 2019 are now limited to ~5 uploads / day with the official API. I've figured out how to use AppleScript to upload videos, but of course that requires the focus of one's entire computer and is not ideal. A "headless" Selenium would allow us to create a faux API, but that doesn't appear possible now either. Commented Oct 17, 2019 at 19:14

1 Answer 1

0

5 years later...
Here's a python solution to upload a video to YouTube using selenium. Should be easy to implement in C#.

from selenium import webdriver
driver = webdriver.Firefox()
driver.implicitly_wait(5) # Wait up 5 sec 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 (◔ _◔)

Sign up to request clarification or add additional context in comments.

2 Comments

OP specifically did ask for C#
Better having a python sample than nothing at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.