Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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# 在Selenium C中获取无头Chrome驱动程序时出错#_C#_Selenium_Selenium Webdriver_Selenium Chromedriver_Headless Browser - Fatal编程技术网

C# 在Selenium C中获取无头Chrome驱动程序时出错#

C# 在Selenium C中获取无头Chrome驱动程序时出错#,c#,selenium,selenium-webdriver,selenium-chromedriver,headless-browser,C#,Selenium,Selenium Webdriver,Selenium Chromedriver,Headless Browser,我在Selenium C#中使用无头chrome驱动程序时出错。我正在做自动化的网站,其中涉及的用户名和密码。没有无头镀铬,它的性能很好。但当我使用无头镀铬时。主要是给了我错误 {"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\" 当前投资组合可折叠>div>div>div>table>tbody>tr:n子项(6)>td:n子项(1)>div>a>span\“}\n

我在Selenium C#中使用无头chrome驱动程序时出错。我正在做自动化的网站,其中涉及的用户名和密码。没有无头镀铬,它的性能很好。但当我使用无头镀铬时。主要是给了我错误

{"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"
当前投资组合可折叠>div>div>div>table>tbody>tr:n子项(6)>td:n子项(1)>div>a>span\“}\n (会话信息:headless chrome=64.0.3282.167..
在此处输入代码

我只在无头chrome中得到这个错误。下面是代码

 var driverService = ChromeDriverService.CreateDefaultService();
            driverService.HideCommandPromptWindow = true;
               ChromeOptions option = new ChromeOptions();
                option.AddArgument("--headless");
                option.AddArgument("--window-size=2160,3840");
            using (var driver = new ChromeDriver(driverService, option))
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
                driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(2);
                driver.Navigate().GoToUrl("https://www.wikifolio.com/");
                label1.Text = "Browser is opened now";                
                    try
                    {

                        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromMinutes(2);
                        IJavaScriptExecutor main = (IJavaScriptExecutor)driver;
                        Task.Delay(10000);

                    main.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[@id=\"page-content\"]/header/div[2]/div/div/nav/div[2]/a[1]")));

                    driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
                        var username = driver.FindElement(By.CssSelector("input#Username"));
                        username.SendKeys("derhenker55@hotmail.com");

                        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);

                        var password = driver.FindElement(By.CssSelector("input#Password"));
                        Task.Delay(1000);
                        password.SendKeys("password");
                        driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);

                        IJavaScriptExecutor loginclick = (IJavaScriptExecutor)driver;
                    Task.Delay(1000);
                    loginclick.ExecuteScript("arguments[0].click();", driver.FindElement(By.CssSelector("form > button.c-button")));

                    }
                    catch(Exception e)
                    {
                    }


            }
这是网站

在这里你可以找到右上角的“登录”按钮

请在这方面帮助我。我们将非常感谢您的帮助。谢谢

var service = ChromeDriverService.CreateDefaultService();
        service.HideCommandPromptWindow = true;
        ChromeOptions option = new ChromeOptions();
        option.AddArgument("--headless");

        driver = new ChromeDriver(service, option);
        wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
        driver.Navigate().GoToUrl("https://www.wikifolio.com/");
        wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("/html/body/div[2]/div[1]")));
        Actions actions = new Actions(driver);
        actions.MoveToElement(driver.FindElement(By.XPath("/html/body/div[2]/div[1]/div[2]/div/div[1]/div[1]/div/div[3]/a[3]"))).Build().Perform();

        Thread.Sleep(2000);
        actions.Click(driver.FindElement(By.CssSelector("#change-language-dialog-container > div > div > div > div > div.c-disclaimer__buttons > div"))).Build().Perform();
        Thread.Sleep(2000);
        driver.FindElement(By.XPath("/html/body/div[2]/header/div[2]/div/div/nav/div[2]/a[1]")).Click();
        wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("//*[@id='Username']")));
        var username = driver.FindElement(By.XPath("//*[@id='Username']"));
        var password = driver.FindElement(By.XPath("//*[@id='Password']"));

        username.Clear();
        username.SendKeys("username");
        password.Clear();
        password.SendKeys("pass");

        IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
        executor.ExecuteScript("arguments[0].click();", driver.FindElement(By.CssSelector("button.c-button:nth-child(8)")));

希望这有帮助!我运行它没有问题。告诉我这是否对您有帮助

我认为它在java中有所不同。