Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用SeleniumWebDriver C在YouTube中使用上载按钮#_C#_Selenium_Youtube - Fatal编程技术网

C# 如何使用SeleniumWebDriver C在YouTube中使用上载按钮#

C# 如何使用SeleniumWebDriver C在YouTube中使用上载按钮#,c#,selenium,youtube,C#,Selenium,Youtube,我正在尝试一个YouTube视频上传器,只需点击一下就可以上传视频。到目前为止,我正设法进入http://www.youtube.com/upload页面,但我找不到使用按钮上传视频的方法 经过一点研究,我发现上传文件的正确方法是uploadVid.SendKeys(“C:\\video.flv”)。到目前为止,我在这一点上: // IWebElement uploadVid = driver.FindElement(By.Id("start-upload-button-single"

我正在尝试一个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"); 
我已经注释掉的行是我迄今为止尝试过的,没有任何成功。我不断得到错误
元素未找到

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

5年后…
下面是一个使用selenium将视频上传到YouTube的python解决方案。应该很容易在C#中实现


备注:
1-要聪明,走得慢但要稳妥
2-YouTube每天的最大上传量是50,但第一天是100

3-截至2019年,youtube api仅限于5次视频上传(◔ _◔)

这是不必要的。YouTube有一个用于上传视频的API:……您根本不需要Selenium。@Arran,我不想使用该API。为什么您不想使用该API?使用该API比尝试使用Selenium更简单、更不容易出错、更高效。Selenium是AP启动时的备用解决方案我不可用或不足。@AntonioPetrov,正如我所说,Selenium无法处理文件上传对话框。YouTube使用HTML5输入字段,Selenium甚至一点也不处理HTML5元素。正如我所说,Selenium无法支持这一点。Selenium在这里不起作用。@Arran您的评论很遗憾没有像我们现在的limi那样成熟ted使用官方API每天上传5次。我已经知道如何使用AppleScript上传视频,但这当然需要整个电脑的关注,这并不理想。一个“无头”的Selenium可以让我们创建一个假的API,但现在看来也不可能。
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