How To select record using Xpath in Selenium - c#

I have a specific record I am attempting to select out of the data grid. Can some help with the XPath to get to that record.
I have tried the following but it doesn't work:
var elementEdit = driver.FindElement(By.XPath(".//tbody[#ClassName='ng-scope']/tr[#ng-binding='" + Username + "']"));
Here is the HTML code:
<tbody>
<!-- ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">pppp</td>
<td class="ng-binding">ppp</td>
<td class="ng-binding">joetester24</td>
<td class="ng-binding">+16195555555</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">gg</td>
<td class="ng-binding">ggg</td>
<td class="ng-binding">joetester99 ggff66</td>
<td class="ng-binding">+18587660891</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Evelina</td>
<td class="ng-binding">Papantoniou</td>
<td class="ng-binding">joetester996</td>
<td class="ng-binding">+12015555555</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Parvati</td>
<td class="ng-binding">Shallow</td>
<td class="ng-binding">joetester990</td>
<td class="ng-binding">+12015555555</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Doutzen</td>
<td class="ng-binding">Kroes</td>
<td class="ng-binding">joetester998</td>
<td class="ng-binding">+12015555555</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Evelina</td>
<td class="ng-binding">Papantoniou</td>
<td class="ng-binding">joetester996</td>
<td class="ng-binding">+12015555555</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Tereza</td>
<td class="ng-binding">Benesova</td>
<td class="ng-binding">joetester995</td>
<td class="ng-binding">+17036928692</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Ashley</td>
<td class="ng-binding">Degenford</td>
<td class="ng-binding">joetester992</td>
<td class="ng-binding">+17036976251</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Joe</td>
<td class="ng-binding">Tester114</td>
<td class="ng-binding">joetester114</td>
<td class="ng-binding">+16195551212</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Jodi Ann</td>
<td class="ng-binding">Paterson</td>
<td class="ng-binding">joetester994</td>
<td class="ng-binding">+17036951997</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Leilani</td>
<td class="ng-binding">Dowding</td>
<td class="ng-binding">joetester993</td>
<td class="ng-binding">+17036149998</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Naureen</td>
<td class="ng-binding">Zaim</td>
<td class="ng-binding">joetester991</td>
<td class="ng-binding">+17036957508</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Joe</td>
<td class="ng-binding">Tester445</td>
<td class="ng-binding">joetester445</td>
<td class="ng-binding">+16195551212</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Joe</td>
<td class="ng-binding">Tester229</td>
<td class="ng-binding">joetester229</td>
<td class="ng-binding">+16195551212</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Juliet</td>
<td class="ng-binding">Cariaga</td>
<td class="ng-binding">joetester997</td>
<td class="ng-binding">+17032715280</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Joe</td>
<td class="ng-binding">Tester825</td>
<td class="ng-binding">joetester825</td>
<td class="ng-binding">+16195551212</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">shdh</td>
<td class="ng-binding">dff</td>
<td class="ng-binding">joetesteroqur</td>
<td class="ng-binding">+16195553164</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">hdjd</td>
<td class="ng-binding">xddd</td>
<td class="ng-binding">joetester0183</td>
<td class="ng-binding">+16195553164</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">djd</td>
<td class="ng-binding">dff</td>
<td class="ng-binding">joetesterm</td>
<td class="ng-binding">+16195553164</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">gf</td>
<td class="ng-binding">ff</td>
<td class="ng-binding">joetesterqww</td>
<td class="ng-binding">+16195553164</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">hhh</td>
<td class="ng-binding">aaaa</td>
<td class="ng-binding">joetester6p</td>
<td class="ng-binding">+16195553164</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">Parvati</td>
<td class="ng-binding">Shallow</td>
<td class="ng-binding">joetester990</td>
<td class="ng-binding">+12015555555</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">hshs</td>
<td class="ng-binding">fff</td>
<td class="ng-binding">joetesterhdhd</td>
<td class="ng-binding">+16195554785</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">test</td>
<td class="ng-binding">test</td>
<td class="ng-binding">joetester234</td>
<td class="ng-binding">+16195551207</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
<tr class="ng-scope" ng-repeat="user in model">
<td class="ng-binding">test</td>
<td class="ng-binding">test</td>
<td class="ng-binding">joetester789</td>
<td class="ng-binding">+16195551207</td>
<td class="ng-binding">
<img class="map-icon" src="../../media/images/google-maps-icon.png" ng-click="viewMap(user.lastKnownPosition.lat, user.lastKnownPosition.lon)">0, 0
</td>
<td class="text-center" ng-click="open(user)"><span class="fa fa-edit"></span>
</td>
</tr>
<!-- end ngRepeat: user in model -->
</tbody>

For example if you want to select joetester24
then the xpath is as follows
//tr[#class='ng-scope']/td[text()='joetester24']

You can try using looping to traverse each element.
var trr = driver.findElements(By.XPath("*//tr[#class='ng-scope']"));
forEach(Iwebelement tr in trr){
var tdd = tr.driver.findElements(By.XPath("*//td[#class='ng-binding']"));
forEach(Iwebelement td in tdd){
if(td.text == "YOUR_MATCHING_TEXT"){// do operations}
// else continue;
}
}
this will take look on each element of your HTML DOM for till your interested element get found

Related

C# Get all the id of the html tag and set inner text for <td></td> tag

I have string html, I want to get all id name of tag in string html.
get string html in file text:
<tr>
<td class="X8">
</td>
<td colspan="6" class="X9"></td>
<td colspan="4" class="X12" id="closedate">
</td>
<td colspan="6" class="X9"></td>
<td colspan="4" class="X12" id="startdate">
</td>
<td class="X8">
</td>
<td class="X8" colspan="3">
</td>
<td class="X8">
</td>
<td colspan="9" class="X9"></td>
<td colspan="6" class="X15" id="totalpayment"></td>
<td class="X8">
</td>
<td class="X8">
</td>
</tr>
<tr>
<td class="X17">
</td>
<td class="X17" colspan="8">
</td>
<td class="X17" colspan="33">
</td>
<td class="X17">
</td>
</tr>
<tr>
<td class="X17">
</td>
<td class="X17" colspan="8">
<td class="X17" colspan="16">
</td>
<td class="X17">
</td>
<td colspan="9" class="X20"></td>
<td colspan="6" class="X23" id="approvaldate"></td>
<td class="X17">
</td>
<td class="X17">
</td>
</tr>
expected results:
closedate, startdate,totalpayment, approvaldate.
Then I want to set inner text for id name tag
(Ex:<td colspan="6" class="X23" id="approvaldate">2018/07/18</td>)
Using c#.Help me, please. Thanks a lot.
What I am understood from your question is you need the id of all in string simple Example Created for you
<form id="form1" runat="server">
<input id="Name" type="text" name="Full Name" runat="server" />
<input id="Email" type="text" name="Email Address" runat="server" />
<input id="Phone" type="text" name="Phone Number" runat="server" />
</form>
foreach (var control in Page.Form.Controls)
{
if (control is HtmlInputControl)
{
var htmlInputControl = control as HtmlInputControl;
string controlName = htmlInputControl.Name;
string controlId = htmlInputControl.ID;
}
}
Another Approach:-
HtmlElement table = testWebBrowser.Document.GetElementById("TableID");
if (table != null)
{
foreach (HtmlElement row in table.GetElementsByTagName("TR"))
{
// ...
}
}

Convert a HTML Table with rowspans to DataTable C#

I need to convert a Html Table to DataTable in C#. I used HtmlAgilityPack but it does not convert it well because of rowspans.
The code I am currently using is:
private static DataTable convertHtmlTableToDataTable()
{
WebClient webClient = new WebClient();
string urlContent = webClient.DownloadString("http://example.com");
string tableCode = getTableCode(urlContent);
string htmlCode = tableCode.Replace(" ", " ");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(htmlCode);
var headers = doc.DocumentNode.SelectNodes("//tr/th");
DataTable table = new DataTable();
foreach (HtmlNode header in headers)
{
table.Columns.Add(header.InnerText);
}
foreach (var row in doc.DocumentNode.SelectNodes("//tr[td]"))
{
table.Rows.Add(row.SelectNodes("td").Select(td => td.InnerText).ToArray());
}
return table;
}
And this is a part of Html Table:
<table class="tabel" cellspacing="0" border="0">
<caption style="font-family:Verdana; font-size:20px;">SEMGRP</caption>
<tr>
<th class="celula" >Ora</th>
<th class="latime_celula celula">Luni</th>
<th class="latime_celula celula">Marti</th>
<th class="latime_celula celula">Miercuri</th>
<th class="latime_celula celula">Joi</th>
<th class="latime_celula celula">Vineri</th>
</tr>
<tr>
<td class="celula" nowrap="nowrap">8-9</td>
<td class="celula" rowspan="2">
<table border="0" align="center">
<tr>
<td nowrap="nowrap" align="center">
Curs
<br />
<a class="link_celula" href="afis_n0.php?id_tip=287&tip=p">Prof</a>
<br />
<a class="link_celula" href="afis_n0.php?id_tip=9&tip=s">Sala</a>
<br />
</td>
</tr>
</table>
</td>
<td class="celula" rowspan="2">
<table border="0" align="center">
<tr>
<td nowrap="nowrap" align="center">
Curs
<br />
<a class="link_celula" href="afis_n0.php?id_tip=287&tip=p">Prof</a>
<br />
<a class="link_celula" href="afis_n0.php?id_tip=12&tip=s">Sala</a>
<br />
</td>
</tr>
</table>
</td>
<td class="celula"> </td>
<td class="celula"> </td>
<td class="celula" rowspan="2">
<table border="0" align="center">
<tr>
<td nowrap="nowrap" align="center">
Curs
<br />
<a class="link_celula" href="afis_n0.php?id_tip=293&tip=p">Prof</a>
<br />
<a class="link_celula" href="afis_n0.php?id_tip=9&tip=s">Sala</a>
<br />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="celula" nowrap="nowrap">9-10</td>
<td class="celula"> </td>
<td class="celula"> </td>
</tr>
<tr>
<td class="celula" nowrap="nowrap">10-11</td>
<td class="celula" rowspan="2">
<table border="0" align="center">
<tr>
<td nowrap="nowrap" align="center"> Curs
<br /><a class="link_celula" href="afis_n0.php?id_tip=303&tip=p">Prof</a>
<br /><a class="link_celula" href="afis_n0.php?id_tip=9&tip=s">Sala</a>
<br />
</td>
</tr>
</table>
</td>
<td class="celula" rowspan="2">
<table border="0" align="center">
<tr>
<td nowrap="nowrap" align="center"> Curs
<br />
<a class="link_celula" href="afis_n0.php?id_tip=331&tip=p">Prof</a>
<br />
<a class="link_celula" href="afis_n0.php?id_tip=14&tip=s">Sala</a>
<br />
</td>
</tr>
</table>
</td>
<td class="celula" rowspan="2">
<table border="0" align="center">
<tr>
<td nowrap="nowrap" align="center"> Curs
<br /><a class="link_celula" href="afis_n0.php?id_tip=330&tip=p">Prof</a>
<br /><a class="link_celula" href="afis_n0.php?id_tip=9&tip=s">Sala</a>
<br />
</td>
</tr>
</table>
</td>
<td class="celula"> </td>
<td class="celula" rowspan="2">
<table border="0" align="center">
<tr>
<td nowrap="nowrap" align="center"> Curs
<br />
<a class="link_celula" href="afis_n0.php?id_tip=293&tip=p">Prof</a>
<br />
<a class="link_celula" href="afis_n0.php?id_tip=10&tip=s">Sala</a> <br />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="celula" nowrap="nowrap">11-12</td>
<td class="celula"> </td>
</tr>
<tr>
I tried some solutions but I did not find any good...
Thanks for any help in advance.

aspx page could not connected with aspx.cs file

So basically i have Web page form named Lab4.aspx but everytime i pressed button, it will always direct to script runat="server" and not the aspx.cs,also the button is changed back to Button_1 when i changed it to BtnSubmit
<script runat="server">
Protected Sub Button1_Click(sender As Object, e As EventArgs)
End Sub
</script>
For the aspx.cs, i already changed the public partial class to public partial class Lab4: System.Web.UI.Page in the aspx.cs and also name the file to Lab4.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Lab4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnSubmit_Click(object sender, EventArgs e)
It would be great if this mystery can be solved because i have tried search for this solution everywhere
Here's the code for the button control on aspx page
<asp:Button ID="BtnSubmit" runat="server" onclick="Button1_Click" Text="Submit"
Width="85px" />
and this is the full code for aspx page
<script runat="server">
Protected Sub Button1_Click(sender As Object, e As EventArgs)
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
font-size: xx-large;
font-family: "Tw Cen MT";
height: 1161px;
}
.style2
{
text-decoration: underline;
}
.style3
{
font-size: x-large;
background-color: #9933FF;
}
.style4
{
width: 100%;
}
.style5
{
width: 243px;
}
.style6
{
width: 609px;
}
.style7
{
width: 243px;
height: 32px;
}
.style8
{
width: 609px;
height: 32px;
background-color: #FFFFFF;
}
.style9
{
height: 32px;
}
.style10
{
background-color: #9966FF;
}
.style11
{
width: 243px;
height: 31px;
}
.style12
{
width: 609px;
height: 31px;
}
.style13
{
height: 31px;
}
.style14
{
width: 303px;
font-size: x-large;
}
.style15
{
width: 303px;
height: 41px;
}
.style16
{
height: 41px;
}
.style17
{
font-size: x-large;
}
.style20
{
width: 254px;
}
.style21
{
width: 254px;
height: 41px;
}
.style22
{
width: 243px;
height: 45px;
}
.style23
{
width: 609px;
height: 45px;
}
.style24
{
height: 45px;
}
.style25
{
width: 303px;
font-size: x-large;
height: 32px;
}
.style26
{
width: 254px;
height: 32px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="style1">
Nasi Tapau O<span class="style2">nline Order
</span>
<br />
<br />
<span class="style3"><span class="style10">Customer's Details
</span>
<br />
<table class="style4">
<tr>
<td class="style5">
Name :
</td>
<td class="style6">
<span class="style3">
<asp:TextBox ID="TxtName" runat="server" Width="545px"></asp:TextBox>
</span>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style7">
</td>
<td class="style8">
</td>
<td class="style9">
</td>
<td class="style9">
</td>
</tr>
<tr>
<td class="style5">
Contact Number :</td>
<td class="style6">
<span class="style3">
<asp:TextBox ID="TxtContactNo" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style6">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
Email :</td>
<td class="style6">
<span class="style3">
<asp:TextBox ID="TxtEmail" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style7">
</td>
<td class="style8">
</td>
<td class="style9">
</td>
<td class="style9">
</td>
</tr>
<tr>
<td class="style5">
Order Details :</td>
<td class="style6">
</td>
<td>
Quantity :
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style6">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
Rice :</td>
<td class="style6">
<asp:RadioButton ID="RBYes" runat="server" Text="Yes" />
<span class="style3"><asp:RadioButton ID="RBNo" runat="server"
style="background-color: #FFFFFF" Text="No" />
</span>
</td>
<td>
<span class="style3">
<asp:TextBox ID="TxtQRice" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style22">
</td>
<td class="style23">
</td>
<td class="style24">
</td>
<td class="style24">
</td>
</tr>
<tr>
<td class="style5">
Side Dishes :</td>
<td class="style6">
<asp:CheckBox ID="CBChicken" runat="server" style="background-color: #FFFFFF" Text="Chicken Curry - RM4.50" />
</td>
<td>
<span class="style3">
<asp:TextBox ID="TxtQChicken" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style7">
</td>
<td class="style8">
<span class="style3">
<asp:CheckBox ID="CBMixed" runat="server" OnCheckedChanged="CBMixed_CheckedChanged" style="background-color: #FFFFFF" Text="Mixed Vegetables - RM2.50" />
</span>
</td>
<td class="style9">
<span class="style3">
<asp:TextBox ID="TxtQMixed" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td class="style9">
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style6">
<span class="style3">
<asp:CheckBox ID="CBGrilled" runat="server" style="background-color: #FFFFFF" Text="Grilled Fish - RM4.00" />
</span>
</td>
<td>
<span class="style3">
<asp:TextBox ID="TxtQGrilled" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style7">
</td>
<td class="style8">
<span class="style3">
<asp:CheckBox ID="CBCondiment" runat="server" style="background-color: #FFFFFF" Text="Condiment - RM1.50" />
</span>
</td>
<td class="style9">
<span class="style3">
<asp:TextBox ID="TxtQCondiment" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td class="style9">
</td>
</tr>
<tr>
<td class="style5">
Beverages :</td>
<td class="style6">
<span class="style3">
<asp:CheckBox ID="CBMangoJ" runat="server" style="background-color: #FFFFFF" Text="Mango Juice - RM3.00" />
</span>
</td>
<td>
<span class="style3">
<asp:TextBox ID="TxtMangoJuice" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style6">
<span class="style3">
<asp:CheckBox ID="CBCendol" runat="server" style="background-color: #FFFFFF" Text="Cendol - RM3.00" />
</span>
</td>
<td>
<span class="style3">
<asp:TextBox ID="TxtCendol" runat="server" Width="165px"></asp:TextBox>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style5">
</td>
<td class="style6">
</td>
<td>
</td>
<td>
</td>
</tr>
<tr>
<td class="style11">
Delivery:</td>
<td class="style12">
<asp:DropDownList ID="DdlDelivery" runat="server">
<asp:ListItem Value="0">Self-pickup</asp:ListItem>
<asp:ListItem Value="1.50">Request For Delivery</asp:ListItem>
</asp:DropDownList>
</td>
<td class="style13">
</td>
<td class="style13">
</td>
</tr>
<tr>
<td class="style11">
</td>
<td class="style12">
</td>
<td class="style13">
<asp:Button ID="BtnSubmit" runat="server" onclick="Button1_Click" Text="Submit"
Width="85px" />
</td>
<td class="style13">
</td>
</tr>
</table>
<br />
<br />
<asp:Label ID="Label1" runat="server" style="background-color: #9966FF"
Text="Thank you for choosing us! Here are you order details :"></asp:Label>
<br />
<br />
</span>
<table class="style4">
<tr>
<td class="style14">
<span class="style17">Name :
</td>
<td class="style20">
<asp:Label ID="lblName" runat="server" Font-Size="X-Large"></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
Telephone :</td>
<td class="style20">
<span class="style17">
<asp:Label ID="LblTel" runat="server"></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
Email :</td>
<td class="style20">
<span class="style17">
<asp:Label ID="lblEmail" runat="server"></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td style="font-size: x-large">
Quantity :</td>
</tr>
<tr>
<td class="style25">
Rice :</td>
<td class="style26">
<span class="style17">
<asp:Label ID="lblRice" runat="server"></asp:Label>
</span>
</td>
<td class="style9">
<span class="style17">
<asp:Label ID="lblQRice" runat="server"></asp:Label>
</span>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
Side Dishes :</td>
<td class="style20">
<span class="style17">
<asp:Label ID="Label6" runat="server" Visible="False"></asp:Label>
</span>
</td>
<td>
<span class="style17">
<asp:Label ID="Label16" runat="server" Visible="False"></asp:Label>
</span>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
<span class="style17">
<asp:Label ID="Label7" runat="server" Visible="False"></asp:Label>
</span>
</td>
<td>
<span class="style17">
<asp:Label ID="Label17" runat="server" Visible="False"></asp:Label>
</span>
</td>
</tr>
<tr>
<td class="style15">
</td>
<td class="style21">
<span class="style17">
<asp:Label ID="Label8" runat="server" Visible="False"></asp:Label>
</span>
</td>
<td class="style16">
<span class="style17">
<asp:Label ID="Label18" runat="server" Visible="False"></asp:Label>
</span>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
<span class="style17">
<asp:Label ID="Label9" runat="server" Visible="False"></asp:Label>
</span>
</td>
<td>
<span class="style17">
<asp:Label ID="Label19" runat="server" Visible="False"></asp:Label>
</span>
</td>
</tr>
<tr>
<td class="style14">
Beverages :</td>
<td class="style20">
<span class="style17">
<asp:Label ID="lblMangoJ" runat="server"></asp:Label>
</span>
</td>
<td>
<span class="style17">
<asp:Label ID="lblQMangoJ" runat="server"></asp:Label>
</span>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
<span class="style17">
<asp:Label ID="lblCendol" runat="server"></asp:Label>
</span>
</td>
<td>
<span class="style17">
<asp:Label ID="lblQCendol" runat="server"></asp:Label>
</span>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
Delivery Method :</td>
<td class="style20">
<span class="style17">
<asp:Label ID="lblDelivery" runat="server"></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
Total :</td>
<td class="style20">
<span class="style17">
<asp:Label ID="lblTotal" runat="server"></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
Grand Total(Inclusive GST) :</td>
<td class="style20">
<span class="style17">
<asp:Label ID="lblTotalWGST" runat="server"></asp:Label>
</span>
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
<tr>
<td class="style14">
</td>
<td class="style20">
</td>
<td>
</td>
</tr>
</table>
<br />
<br />
</div>
</form>
</body>
</html>
Your aspx page should actually start with something like this.
<%# Page Title="" Language="C#" MasterPageFile="" AutoEventWireup="true" CodeBehind="Lab4.aspx.cs" Inherits="" %>
CodeBehind="Lab4.aspx.cs" is the place where you specify which is your code behind file in C#.
Every aspx will have a page directive which will tell compiler where to look for its code file
<%# Page CodeFile="Lab4.aspx.cs" %>
documentation

Failed to load pdf file generated by itextsharp

I am facing an error in generating a proper PDF Document. the code i have, can generate a pdf document, it can download the document, but the issue is i cannot view the view the document. This is the Page I am trying to export to pdf.
Here is my code so far:
ASPX:
<asp:Button ID="btnDownload" CssClass="btn" runat="server" Text="Download Invoice" OnClick="btnDownload_Click" />
<asp:Panel ID="pnl" runat="server">
<div id="page-wrap">
<textarea id="header" style="height: 30px">PAYMENT DETAILS</textarea>
<div id="identity">
<textarea style="background-color: #F7F7F7;" readonly="readonly" id="address">My Name
My Street Address
Phone: 111-111-111</textarea>
<div id="logo">
<div id="logoctr">
</div>
<div id="logohelp">
<input id="imageloc" readonly="readonly" type="text" size="50" value="" /><br />
(max width: 540px, max height: 100px)
</div>
<img id="image" src="images/logo.png" alt="logo" />
</div>
</div>
<div style="clear: both"></div>
<div id="customer">
<textarea id="tbCustomer" readonly="readonly" runat="server"></textarea>
<table id="meta">
<tr>
<td class="meta-head">Payment ID</td>
<td>
<textarea readonly="readonly" runat="server" id="tbPID"></textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td>
<textarea id="date" readonly="readonly" runat="server"></textarea></td>
</tr>
<tr>
<td class="meta-head">Amount Due</td>
<td>
<div class="due">
$
<asp:Label ID="lblTotal" runat="server" Text="Total"></asp:Label>
</div>
</td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>Property Title</th>
<th>Description</th>
<th>Status</th>
<th>Invoiced By</th>
<th>Total Payment</th>
</tr>
<tr class="item-row">
<td class="item-name">
<div class="delete-wpr">
<textarea readonly="readonly" id="tbTitle" runat="server"></textarea>
</div>
</td>
<td class="description">
<div contenteditable="true" id="tbDetail" class="blank" runat="server">
</div>
</td>
<td>
<textarea id="tbStatus" runat="server" readonly="readonly">PAID</textarea></td>
<td>
<textarea class="qty" readonly="readonly" id="tbInvoicedBy" runat="server"></textarea></td>
<td><span class="price">$
<asp:Label ID="tbTotal1" runat="server" Text="Total"></asp:Label></span></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Vaccant</td>
<td class="total-value">
<div id="subtotal">$<asp:Label ID="lblVaccant" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Maintainance</td>
<td class="total-value">
<div id="total">$<asp:Label ID="lblMaintainance" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Property Insurance</td>
<td class="total-value">
<div id="Insurance">$<asp:Label ID="lblInsurance" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Dewa Bill</td>
<td class="total-value">
<div id="dewa">$<asp:Label ID="lblDewa" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Furnishing Cost</td>
<td class="total-value">
<div id="FurnishingCost">$<asp:Label ID="lblFurnishing" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Cleaning Fees</td>
<td class="total-value">
<div id="CleaningFees">$<asp:Label ID="lblCleaning" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">House Keeping</td>
<td class="total-value">
<div id="HouseKeeping">$<asp:Label ID="lblHouseKeeping" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Next Rent Due</td>
<td class="total-value">
<div id="paid">$<asp:Label ID="lblNextRent" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Rental Comission</td>
<td class="total-value">
<div id="RentalComission">$<asp:Label ID="lblRentalComission" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Credit Card Fees</td>
<td class="total-value">
<div id="CreditCardFees">$<asp:Label ID="lblCreditCardFees" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Pest Control</td>
<td class="total-value">
<div id="PestControl">$<asp:Label ID="lblPestControl" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Chillar Utilities</td>
<td class="total-value">
<div id="ChillarUtilities">$<asp:Label ID="lblChillarUtilities" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Du, etisilate wifi</td>
<td class="total-value">
<div id="DuEtisilatewifi">$<asp:Label ID="lblDuEtisilateWifi" runat="server" Text=""></asp:Label></div>
</td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line balance">Total Payment</td>
<td class="total-value balance">
<div class="due">$<asp:Label ID="lblTotal2" runat="server" Text=""></asp:Label></div>
</td>
</tr>
</table>
<div id="terms">
<h5>Terms</h5>
<textarea readonly="readonly">These payment details are final and non negotiable.</textarea>
</div>
</div>
</asp:Panel>
ASPX.CS
public void ExportToPDF()
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Panel.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnl.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
sw.Close();
htmlparser.Close();
Response.Write(pdfDoc);
Response.End();
}
also it says the HTMLWorker class is obsolete.

Getting correct XPATH expression for DIV CLASS

i am trying to traverse an html document:
<body class="style_0">
<div>
<div class="style_1">Pending Test List</div>
<table style=" width: 100%;" id="AUTOGENBOOKMARK_4365445353431356880">
<col>
<col>
<tbody>
<tr>
<td style="vertical-align: baseline;">
<div class="style_4">Pending Test List</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_5">SOME AGENCY Laboratories, Inc.</div>
</td>
</tr>
</tbody>
</table>
<table class="style_6" style=" width: 4.531in;" id="AUTOGENBOOKMARK_5083738604442918131">
<col style=" width: 1in;">
<col class="style_7" style=" width: 0.75in;">
<col class="style_8" style=" width: 0.6in;">
<col style=" width: 0.75in;">
<col style=" width: 2.375in;">
<tbody>
<tr class="style_9" style=" height: 0.5in;">
<td style="vertical-align: middle;">
<div class="style_10">Report Range:</div>
</td>
<td style="vertical-align: middle;">
<div class="style_11">01/01/2012</div>
</td>
<td style="vertical-align: middle;">
<div class="style_12">through</div>
</td>
<td style="vertical-align: middle;">
<div class="style_13">01/31/2012</div>
</td>
<td style="vertical-align: middle;">
<div class="style_14">(by Date Entered)</div>
</td>
</tr>
</tbody>
</table>
<table class="style_15" style=" width: 100%;" id="AUTOGENBOOKMARK_7602283385844673591" iid="/526
(QuRs78576248:0)">
<col style=" width: 0.75in;">
<col style=" width: 1.25in;">
<col style=" width: 1in;">
<col style=" width: 1.5in;">
<col style=" width: 1.5in;">
<col style=" width: 1.5in;">
<col>
<thead>
<tr>
<td colspan="4" style="vertical-align: baseline;"></td>
<td style="vertical-align: baseline;"></td>
<td style="vertical-align: baseline;"></td>
<td style="vertical-align: baseline;"></td>
</tr>
<tr>
<td style="vertical-align: baseline;">
<div class="style_16">Entered</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_16">Spec. ID</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_16">Batch/Pos.</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_16">Test</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_16">Client ID</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_16">Client Name</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_16">Agency</div>
</td>
</tr>
</thead>
<tbody>
<tr>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">1/30/12</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_19">ZZ324sdf</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">51446 / 75</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">HOLD_DE</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">234234</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">smith, john</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">PPPM-6P - SOME AGENCY</div>
</td>
</tr>
<tr>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">1/31/12</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_19">SFD3434</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">51668 / 17</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">HOLD_DE</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">FOY, EL</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">FOY, ALEX</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">someagency & Associates LLC</div>
</td>
</tr>
<tr>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">1/31/12</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_19">SFD3434</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">51668 / 25</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">HOLD_DE</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">JAMISON, PA</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">JAMISON, ROY</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">someagency & Associates LLC</div>
</td>
</tr>
<tr>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">1/31/12</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_19">SFD3434</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_18">51669 / 34</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">HOLD_DE</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">NEWMAN, SO</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">NEWMAN, ALEX</div>
</td>
<td class="style_17" style="vertical-align: baseline;">
<div class="style_20">someagency & Associates LLC</div>
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2" style="vertical-align: baseline;">
<div class="style_21">Total Tests:</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_22">4</div>
</td>
<td style="vertical-align: baseline;"></td>
<td style="vertical-align: baseline;"></td>
<td style="vertical-align: baseline;"></td>
<td style="vertical-align: baseline;"></td>
</tr>
</tfoot>
</table>
<table style=" width: 100%;" id="AUTOGENBOOKMARK_8507236727661888074">
<col>
<col>
<col>
<tbody>
<tr>
<td style="vertical-align: baseline;">
<div class="style_2">
<br>Feb 13, 2012 9:37 AM</div>
</td>
<td style="vertical-align: baseline;">
<div class="style_3">
<br>
<div style="text-align:center;">Page 1</div>
</div>
</td>
<td style="vertical-align: baseline;"></td>
</tr>
</tbody>
</table>
</div>
</body>
for this data:
so far i have this:
foreach (var row in htmlSnippet.DocumentNode.SelectNodes("//table[#class = 'style_15']/tbody/tr"))
{
foreach (var cell in row.SelectNodes("div[#class='*']"))
{
textBox1.Text = cell.InnerHtml.ToString();
}
}
however i am not returning anything!
this line is working:
//table[#class = 'style_15']/tbody/tr
but this does not return anthing:
("div[#class='*']"))
please let me know what i am doing wrong! i need help returning every piece of data as shown in the image (except for the field names)
The * is typically used for matching any element or attribute name, not any value. If you want to match all div elements having a class attribute with any value, just use #class.
foreach (var row in htmlSnippet.DocumentNode.SelectNodes("//table[#class = 'style_15']/tbody/tr/td"))
{
foreach (var cell in row.SelectNodes("div[#class]"))
{
textBox1.Text = cell.InnerHtml.ToString();
}
}
You probably want simply div[#class]—a div element that has a class attribute.
Oh, it's also worth noting that the HTML/XML sample you provided is not well-formed. I had to remove all the col elements, and close the br elements. Maybe, for C#, that's an issue... I know it is for XSL in general... not sure about XPath.
I don't have time to code up a C# example, but here's a simple XSL:
<xsl:template match="/">
<so>
<xsl:apply-templates select="//table[#class = 'style_15']/tbody/tr"/>
</so>
</xsl:template>
<xsl:template match="div[#class]">
<xsl:copy-of select="."/>
</xsl:template>
I get this output:
<so>
<div class="style_18">1/30/12</div>
<div class="style_19">ZZ324sdf</div>
<div class="style_18">51446 / 75</div>
<div class="style_20">HOLD_DE</div>
<div class="style_20">234234</div>
<div class="style_20">smith, john</div>
<div class="style_20">PPPM-6P - SOME AGENCY</div>
<div class="style_18">1/31/12</div>
<div class="style_19">SFD3434</div>
<div class="style_18">51668 / 17</div>
<div class="style_20">HOLD_DE</div>
<div class="style_20">FOY, EL</div>
<div class="style_20">FOY, ALEX</div>
<div class="style_20">someagency & Associates LLC</div>
<div class="style_18">1/31/12</div>
<div class="style_19">SFD3434</div>
<div class="style_18">51668 / 25</div>
<div class="style_20">HOLD_DE</div>
<div class="style_20">JAMISON, PA</div>
<div class="style_20">JAMISON, ROY</div>
<div class="style_20">someagency & Associates LLC</div>
<div class="style_18">1/31/12</div>
<div class="style_19">SFD3434</div>
<div class="style_18">51669 / 34</div>
<div class="style_20">HOLD_DE</div>
<div class="style_20">NEWMAN, SO</div>
<div class="style_20">NEWMAN, ALEX</div>
<div class="style_20">someagency & Associates LLC</div>
</so>
This is just an intermediate output to show that the XPath is working correctly.
Hope this helps.

Categories