如何使用 Selenium WebDriver C# 在 YouTube 中使用上传按钮 [英] How to usethe upload button in YouTube using Selenium WebDriver C#

查看:38
本文介绍了如何使用 Selenium WebDriver C# 在 YouTube 中使用上传按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个 YouTube 视频上传器,只需单击一下即可上传视频.到目前为止,我设法进入 http://www.youtube.com/upload 页面,但我找不到使用按钮上传视频的方法.

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.

经过一些研究,我发现上传文件的正确方法是 uploadVid.SendKeys("C:\\video.flv");.到目前为止,我处于这一点:

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"); 

我注释掉的行是我迄今为止尝试过但没有成功的行.我不断收到错误 element not found .

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

我在 VS2013、WPF 中使用 C# Selenium WebDriver.

I use C# Selenium WebDriver in VS2013, WPF.

推荐答案

5 年后...
这是使用 selenium 将视频上传到 YouTube 的 Python 解决方案.在 C# 中应该很容易实现.

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

<小时>

注意事项:
1 - 聪明,缓慢但坚定;
2 - YouTube 每天最大上传次数为 50,但第一天为 100;
3 - 截至 2019 年,youtube api 仅限于 5 个视频上传 (◔ _◔)


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

这篇关于如何使用 Selenium WebDriver C# 在 YouTube 中使用上传按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆