Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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# 奇异值返回_C#_Selenium_Phantomjs - Fatal编程技术网

C# 奇异值返回

C# 奇异值返回,c#,selenium,phantomjs,C#,Selenium,Phantomjs,一,;我在PhantomJsdriver中使用Selenium using (IWebDriver driver = new PhantomJSDriver()) { driver.Navigate().GoToUrl("http://www.google.com"); var content = driver.PageSource; >

一,;我在PhantomJsdriver中使用Selenium

 using (IWebDriver driver = new PhantomJSDriver())
    {                   

                driver.Navigate().GoToUrl("http://www.google.com");                   

               var  content = driver.PageSource;  >> wrong content return
    }
内容始终获得
“”

但是
driver.PageSource
正确地获取了网站的全部内容


那是怎么回事?非常奇怪的行为。

您遇到了计时问题。在加载整个
DOM
内容之前检索内容。最简单的检查方法是在检索内容之前添加
Thread.Sleep(2000)
。但是,这不是一个好的做法,因此在检索内容之前利用驱动程序提供的事件,或者在检索内容之前等待加载特定的
DOM
元素。

感谢您的及时回复,但这并不正确,因为我可以在调试点(使用Visual studio)查看这两个值,真奇怪,将鼠标悬停在content和driver.pagesource上,它们显示不同的值。我相信所有的DOM内容都已完全加载,否则,我无法查看驱动程序。PageSource是完整的页面内容。好的,我尝试了2000,可能太快了,所以我增加到了Thread.Sleep(10000),变量内容现在得到了正确的值。谢谢