C#selenium加载html

C#selenium加载html,c#,selenium,selenium-webdriver,C#,Selenium,Selenium Webdriver,我想将html从WebClient()加载到selenium驱动程序。 我有: 如果我像本地html文件一样保存它,然后在上面导航 driver.Navigate().GoToUrl(localfile); 它不会有帮助,因为它会请求在线资源。这花的时间太长了 我还尝试了Javascript执行器 IJavaScriptExecutor js = driver as IJavaScriptExecutor; string title = (string)js.Exec

我想将html从
WebClient()
加载到selenium驱动程序。 我有:

如果我像本地html文件一样保存它,然后在上面导航

 driver.Navigate().GoToUrl(localfile);
它不会有帮助,因为它会请求在线资源。这花的时间太长了

我还尝试了Javascript执行器

IJavaScriptExecutor js = driver as IJavaScriptExecutor;
            string title = (string)js.ExecuteScript("document.write('" + HTML +"')"); 
但那是行不通的

我这样做的原因是对我来说,解析html最简单的方法是使用Selenium驱动程序,我尝试使用
HtmlAgilityPack
,但我以前从未使用过它,而且与Selenium按Id选择、按类名选择等相比,它似乎复杂得多

我可以在本地加载selenium吗? 有类似于selenium的html解析器吗

试试CsQuery

它使解析HTML变得非常简单,方式与jQuery非常相似:

var document = CsQuery.CQ.CreateDocument(html);
foreach (var element in document.Select("ul.somelist > li.thread")) 
{
    // do something with element
}
var document = CsQuery.CQ.CreateDocument(html);
foreach (var element in document.Select("ul.somelist > li.thread")) 
{
    // do something with element
}