Beginner
Beginner

Reputation: 1030

HTML agility pack QuerySelector returns null

I'm using Fizzler for Html Agility Pack. This is my selector which works fine width jquery when I test it in firebug:

$('table.adsh>tbody:nth-child(1)>tr:nth-child(4) table tr:nth-child(1)>td:nth-child(2)')

But this line of code returns null in C# code:

var item = page.QuerySelector("table.adsh>tbody:nth-child(1)>tr:nth-child(4) table tr:nth-child(1)>td:nth-child(2)");

item is always null. Is there any thing wrong with my selector?

Any help is appreciated in advance.

Upvotes: 4

Views: 1673

Answers (1)

Beginner
Beginner

Reputation: 1030

I solved the problem. I printed out the page.QuerySelector("table.adsh").InnerHtml; and saw that it does not include any tbody tag. But when I Inspect Element the page in Chrome or FireFox the table includes tbody tag. The reson is that the original Html code does not include tbody and when I Inspect Element the table the browser adds tbody to the inspected code. In the page source I can see the original html.

Read more here: Why does firebug add <tbody> to <table>?.

So I just removed tbody from my selector.

Upvotes: 2

Related Questions