硒无法与Google无头模式配合使用:无法找到元素

时间:2019-04-29 21:18:22

标签: c# selenium selenium-chromedriver

我需要使用Google headless,但出现此错误

  

OpenQA.Selenium.NoSuchElementException     HResult = 0x80131500     消息=没有这样的元素:无法找到元素:{“方法”:“名称”,“选择器”:“标识符”}     (会议信息:无头铬= 74.0.3729.108)     (驱动程序信息:chromedriver = 74.0.3729.6(255758eccf3d244491b8a1317aa76e1ce10d57e9-refs / branch-heads / 3729 @ {#29}),platform = Windows NT 10.0.17763 x86_64)     Source = WebDriver

我的代码配置:

 void Run()
 {
// Setup Selenium
            chromeOptions = new ChromeOptions();
            chromeOptions.AddArguments("--no-sandbox");
            chromeOptions.AddArguments("--headless");
            chromeOptions.AddArguments("--window-size=1280,800");
            chromeOptions.AddArguments("disable-gpu");
            driver = new ChromeDriver(chromeOptions);

            // Perform the Login actions


            YoutubeLogin();
}
public void YoutubeLogin()
        {

            Thread.Sleep(2000);
            driver.Navigate().GoToUrl("https://www.youtube.com/account");
            Thread.Sleep(1000);
            driver.FindElement(By.Name("identifier")).SendKeys(youtubeEmail);
            Thread.Sleep(1000);
            driver.FindElement(By.ClassName("CwaK9")).Click();
            Thread.Sleep(1000);
            driver.FindElement(By.Name("password")).SendKeys(youtubePassword);
            Thread.Sleep(1000);
            driver.FindElement(By.ClassName("CwaK9")).Click();
            Thread.Sleep(1000);
        }

在线

driver.FindElement(By.Name("identifier")).SendKeys(youtubeEmail);

0 个答案:

没有答案