Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.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# .NETphantomjs+;selenium无法获取元素_C#_.net_Selenium_Phantomjs - Fatal编程技术网

C# .NETphantomjs+;selenium无法获取元素

C# .NETphantomjs+;selenium无法获取元素,c#,.net,selenium,phantomjs,C#,.net,Selenium,Phantomjs,当我单独使用Selenium时,一切都很好,但是当我尝试使用phantomjs时,我在查找元素时得到空值 static void Main() { IWebDriver driver = new PhantomJSDriver(); driver.Navigate().GoToUrl("https://sellercentral.amazon.de/gp/homepage.html"); var username = d

当我单独使用Selenium时,一切都很好,但是当我尝试使用phantomjs时,我在查找元素时得到空值

        static void Main()
    {

        IWebDriver driver = new PhantomJSDriver();

        driver.Navigate().GoToUrl("https://sellercentral.amazon.de/gp/homepage.html");
        var username = driver.FindElement(By.Id("username"));
        var password = driver.FindElement(By.Id("password"));
        username.SendKeys("*************************");
        password.SendKeys("*************");
        driver.FindElement(By.Id("sign-in-button")).Submit();
        string messagesURL = "https://sellercentral.amazon.de/gp/communication-manager/inbox.html/ref=ag_cmin__cmin?ie=UTF8&clcmResponseTimeSuboptions=&dateExactEnd=&dateExactStart=&dateFilter=&itemsPerPage=20&marketplaceId=A1PA6795UKMFR9&otherPartyId=&pageNum=1&refIndex=40&searchBoxText=&showFilters=0&sortBy=ArrivalDate&sortOrder=Descending";
        driver.Navigate().GoToUrl(messagesURL);
        ParseMessages(driver);

    }

    public static void ParseMessages(IWebDriver driver) {
        var node = driver.FindElements(By.ClassName("list-row-white"));
        foreach (var n in node) {
            var refNo = n.FindElement(By.ClassName("data-display-field-border-lbr"));
            Console.WriteLine(mi.refNo);

        }
    }
在这行代码中,我得到null:
var node=driver.FindElements(By.ClassName(“列表行白色”)
但当我将selenium单独用于实际浏览器时,一切都正常。但我想让事情变得无头


我是phantomJS新手,如果我正确实现了它,如果我的代码正确,请纠正我。

在某些情况下,phantomJS在处理css相关的东西或元素类时会遇到问题。
在这种情况下,将定位器转换为XPath可以解决问题

// Thread.Sleep(3000) // Please, replace me with WebDriverWait ^_^ 
var node = driver.FindElements(By.XPath("//*[contains(@class,'list-row-white')]"));
另一点是,PhantomJS比任何其他浏览器都快得多。
尝试插入线程。在失败的代码行之前休眠


如果代码将通过--请用正确的WebDriverWait表达式替换它

那么您不会得到
null
。如果
.FindElements
找不到任何内容,您将得到一个空集合。您是否检查了该行前面的URL和页面源代码?我不确定亚马逊是否是使用无头浏览器的最佳网站。毕竟,这是一个非常重JavaScript的网站。你的权利,正如我查看pageSource时,没有类名“list row white”。是否有办法启用所有pageSource加载?谢谢。我试过XPath、Thread、Sleep和WebDriverWait,但没有成功。无论如何,谢谢你。PhantomJS有没有加载脚本的方法?当我查看页面源时,我正在查找的元素不在那里。Wylan,请您再试一次好吗?请在加载页面后立即将浏览器窗口分辨率设置为1024x768或更大。有时候,PhantomJS会遇到浏览器窗口小的问题driver.Navigate().gotour(“);driver.Manage().Window.Size=新大小(1024768);感谢@dmytrozari这是我使用django、selenium、phantomjs和firefox webdriver时的情况(没有尝试其他webdriver)。加载页面后立即调用self.selenium.maximize_Window()就成功了。