如何使用Selenium WebDriver c#在YouTube中使用上传按钮

本文关键字:按钮 YouTube Selenium 何使用 WebDriver | 更新日期: 2023-09-27 17:53:00

我想让一个YouTube视频上传器上传一个视频点击一下。到目前为止,我正在设法到达http://www.youtube.com/upload页面,但我找不到一种方法来使用按钮上传我的视频。

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

    //  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

我在VS2013, WPF中使用c# Selenium WebDriver

如何使用Selenium WebDriver c#在YouTube中使用上传按钮

5年后…
下面是一个使用selenium将视频上传到YouTube的python解决方案。应该很容易在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个视频上传(()

)