Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.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# 将IwebElement传递到html敏捷包C中#_C#_Selenium_Html Agility Pack - Fatal编程技术网

C# 将IwebElement传递到html敏捷包C中#

C# 将IwebElement传递到html敏捷包C中#,c#,selenium,html-agility-pack,C#,Selenium,Html Agility Pack,我在这方面遇到了麻烦: 我有我公司的内部HTML。在这一页中,我有一个表格。我想在C#中将HTML表转换为DataTable: 这是我的密码: IWebElement ie = driver.FindElement(By.XPath(".//*[@id='frmClaimSearch']/div[2]/div[1]/div/table")); ie.GetAttribute("innerHTML");//get Element of the HTML var doc = new HtmlDoc

我在这方面遇到了麻烦:

我有我公司的内部HTML。在这一页中,我有一个表格。我想在C#中将HTML表转换为DataTable:

这是我的密码:

IWebElement ie = driver.FindElement(By.XPath(".//*[@id='frmClaimSearch']/div[2]/div[1]/div/table"));

ie.GetAttribute("innerHTML");//get Element of the HTML
var doc = new HtmlDocument();

doc.Load("????");

var nodes = doc.DocumentNode.SelectNodes(".//*[@id='frmClaimSearch']/div[2]/div[1]/div/table/tr");
var table = new DataTable("MyTable");

var headers = nodes[0]
            .Elements("th")
            .Select(th => th.InnerText.Trim());
foreach (var header in headers)
{
    table.Columns.Add(header);
}
var rows = nodes.Skip(1).Select(tr => tr
            .Elements("td")
            .Select(td => td.InnerText.Trim())
            .ToArray());
foreach (var row in rows)
{
    table.Rows.Add(row);
}
@id='frmClaimSearch']/div[2]/div[1]/div/table/tr");
var table = new DataTable("MyTable is my XPath of Table.
但这些代码行不起作用。我试了很多。请帮帮我。非常感谢。

使用
LoadHtml()
方法而不是
Load()
从HTML字符串填充
HtmlDocument

IWebElement ie = driver.FindElement(By.XPath(".//*[@id='frmClaimSearch']/div[2]/div[1]/div/table"));

string innerHtml = ie.GetAttribute("innerHTML");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(innerHTML);

.......