How can I give cellpadding,cellspacing of a table in asp.net - c#

I want to set width, height, cllpadding and cellspacing and valign of a table but I did not find these attributes in asp.Net. (But these tags are available in PHP Dreamweaver) Guide me how can I set these four for a table in asp.Net. I have visual studio 2012.
<table width="1332" height="231" border="1" >
<tr>
<td colspan="2" rowspan="2">Region</td>
<td height="21" colspan="3"><span id="result_box" lang="ar" xml:lang="ar">المجموع العام</span></td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2">مسندم</td>
<td colspan="2" rowspan="2"><span id="result_box2" lang="ar" xml:lang="ar">منطقة</span></td>
</tr>
<tr>
<td height="23" colspan="3">Grand Total</td>
<td colspan="2"> </td>
<td colspan="2">Musandam</td>
<td colspan="2">Al-wusta</td>
<td colspan="2">Alburaimi</td>
<td colspan="2">Al-Dhahira</td>
<td colspan="2">Dohfar</td>
<td colspan="2">Al-dhakhila</td>
<td colspan="2">Al-sharqiya(n)</td>
<td colspan="2">Al-sharqiyah</td>
<td colspan="2">Albatiniah(s)</td>
<td colspan="2">Al-Albatinah</td>
<td colspan="2">Muscat</td>
</tr>
<tr>
<td colspan="2">Gender</td>
<td width="77"><span id="result_box8" lang="ar" xml:lang="ar">مجموع</span></td>
<td width="24">١</td>
<td width="24">ذ</td>
<td width="10">١</td>
<td width="14">ذ</td>
<td width="45">١</td>
<td width="16">ذ</td>
<td width="11">١</td>
<td width="34">ذ</td>
<td width="13">١</td>
<td width="39">ذ</td>
<td width="25">١</td>
<td width="32">ذ</td>
<td width="16">١</td>
<td width="20">ذ</td>
<td width="28">١</td>
<td width="32">ذ</td>
<td width="28">١</td>
<td width="49">ذ</td>
<td width="42">١</td>
<td width="25">ذ</td>
<td width="26">١</td>
<td width="44">ذ</td>
<td width="38">١</td>
<td width="29">ذ</td>
<td width="22">١</td>
<td width="17">ذ</td>
<td colspan="2"><span id="result_box3" lang="ar" xml:lang="ar">جنس</span></td>
</tr>
<tr>
<td colspan="2">Specialization</td>
<td>Total</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td>F</td>
<td>M</td>
<td colspan="2"><span id="result_box4" lang="ar" xml:lang="ar">تخصص</span></td>
</tr>
<tr>
<td width="68" rowspan="4" valign="top">Foundation</td>
<td width="152" valign="top">Engnieering</td>
<td height="23">120</td>
<td>48</td>
<td>72</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td width="105" valign="top">الهندسة</td>
<td width="37" rowspan="4" valign="top">مؤسسة</td>
</tr>
<tr>
<td valign="top">Information Technology</td>
<td>213</td>
<td>147</td>
<td>66</td>
<td>1</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td>1</td>
<td>1</td>
<td>0</td>
<td>0</td>
<td valign="top">تكنولوجيا المعلومات</td>
</tr>
<tr>
<td rowspan="2" valign="top">Total</td>
<td rowspan="2">313</td>
<td height="28">195</td>
<td>138</td>
<td>1</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td>2</td>
<td>2</td>
<td>0</td>
<td>0</td>
<td rowspan="2" valign="top">إجمالي</td>
</tr>
<tr>
<td height="26" colspan="2">313</td>
<td colspan="2">3</td>
<td colspan="2">0</td>
<td colspan="2">4</td>
<td colspan="2">0</td>
<td colspan="2">4</td>
<td colspan="2">0</td>
<td colspan="2">4</td>
<td colspan="2">0</td>
<td colspan="2">4</td>
<td colspan="2">0</td>
<td colspan="2">4</td>
<td colspan="2">0</td>
</tr>
</table>
Height width valign top is also not available in visual studio

If you do like to code it using only HTML, this is done like this :
<table cellspacing="10px" cellpadding="10px" style = "height = 200px;width:200px;">
Note : cellspacing and cellpadding is obsolete, I think in HTML5,But if you give it a try, its still working(but maybe your editor will give you warning message on that like on Eclipse IDE). And adding css style in your HTML tag is dirty and hard to maintain when it comes to redesigning your page.
Using css :
table { border-spacing: 5px;/*use to work like cellspacing */
width : 200px;
height:200px;
}
th, td { padding: 5px; } /*use to work like cellpadding */

Add one class for your table in Visual Studio and apply it using the class in CSS like below. For example i am going to assign the class mycuststyle.
table.mycuststyle
{
border-spacing:3px;
width:400px;
height:400px;
}
table.mycuststyle td, table.mycuststyle th
{
padding:10px;
vertical-align:middle;
text-align:left;
}

<html>
<head>
<title>Cell Spacing & Cell Padding</title>
</head>
<Body>
<table border="border">
<tr>
<th colspan="2">Cuisine</th>
</tr>
<tr>
<th>Non Veg</th>
<th>Veg</th>
</tr>
<tr>
<td>
<table border="border">
<tr>
<th> </th>
<th>Fish</th>
<th>Chicken</th>
</tr>
<tr>
<th>Cost</th>
<td>450 </td>
<td>550</td>
</tr>
</table>
<table border="border">
<tr>
<th>Idli</th>
<th>Dosa</th>
</tr>
<tr>
<td>35</td>
<td>40</td>
</tr>
</table>
</td>
</tr>
</table>
</Body>
</html>

Related

iText 7 pdfHTML extension doesn't implement all of my CSS when converting my html to pdf in my C# utility

I have the following HTML:
<html>
<head>
<style>
.styled-table {
border-collapse: collapse;
margin: 25px 0;
font-size: 0.9em;
font-family: sans-serif;
min-width: 400px;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.15);
width: 100%;
}
.styled-table thead tr {
background-color: #004298;
color: #ffffff;
text-align: left;
}
.styled-table th,
.styled-table td {
padding: 12px 15px;
}
.styled-table tbody tr {
border-bottom: 1px solid #dddddd;
}
.styled-table tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
.styled-table tbody tr:last-of-type {
border-bottom: 2px solid #004298;
}
.styled-table tbody tr.active-row {
font-weight: bold;
color: #004298;
}
</style>
</head>
<body>
<table class='styled-table'>
<thead>
<tr class='active-row'>
<th>Allowed access control list</th>
</tr>
</thead>
<tr class='active-row'>
<td>
<table class='styled-table'>
<tr>
<td>172.16.40.250 - Blue Coat SG-VA Series>show allowed-access</td>
</tr>
<tr>
<td>192.168.1.69 255.255.255.255</td>
</tr>
<tr>
<td>192.168.1.71 255.255.255.255</td>
</tr>
</table>
</td>
</tr>
</table>
<p>
<table class='styled-table'>
<thead>
<tr class='active-row'>
<th>Proxy Client and Unified Agent settings</th>
</tr>
</thead>
<tr class='active-row'>
<td>
<table class='styled-table'>
<tr>
<td colspan='2'>172.16.40.250 - Blue Coat SG-VA Series>show clients</td>
</tr>
<tr>
<td colspan='2'>Client Manager configuration</td>
</tr>
<tr>
<td><strong> Activation </strong></td>
<td> disabled</td>
</tr>
<tr>
<td><strong> Host </strong></td>
<td> from client request</td>
</tr>
<tr>
<td><strong> Install Port </strong></td>
<td> 8084</td>
</tr>
<tr>
<td><strong> Keyring </strong></td>
<td> default</td>
</tr>
<tr>
<td><strong> Manager Version </strong></td>
<td> 1</td>
</tr>
<tr>
<td><strong> PxC Software Upgrade URL </strong></td>
<td> </td>
</tr>
<tr>
<td><strong> PxC Archive Version </strong></td>
<td> 3.4.3.2</td>
</tr>
<tr>
<td><strong> PxC MSI file size </strong></td>
<td> 10951680 bytes</td>
</tr>
<tr>
<td><strong> PxC BSX file size </strong></td>
<td> 9668837 bytes</td>
</tr>
<tr>
<td><strong> UA Software Upgrade URL </strong></td>
<td> </td>
</tr>
<tr>
<td><strong> UA Archive Version </strong></td>
<td> 4.7.1.188819</td>
</tr>
<tr>
<td><strong> UA32 MSI file size </strong></td>
<td> 4939776 bytes</td>
</tr>
<tr>
<td><strong> UA64 MSI file size </strong></td>
<td> 6496256 bytes</td>
</tr>
<tr>
<td><strong> UA OSX ZIP file size </strong></td>
<td> 11663933 bytes</td>
</tr>
<tr>
<td><strong> Update Interval </strong></td>
<td> 120 minutes</td>
</tr>
<tr>
<td><strong> Uninstall Password </strong></td>
<td> Disabled</td>
</tr>
<tr>
<td colspan='2'>Client Manager Web-filter configuration</td>
</tr>
<tr>
<td><strong> Activation </strong></td>
<td> disabled</td>
</tr>
<tr>
<td><strong> Safe Search </strong></td>
<td> disabled</td>
</tr>
<tr>
<td><strong> HTTPS Filtering </strong></td>
<td> enabled</td>
</tr>
<tr>
<td><strong> Default Action </strong></td>
<td> allow</td>
</tr>
<tr>
<td><strong> Failure Mode </strong></td>
<td> closed</td>
</tr>
<tr>
<td colspan='2'> Log Settings </td>
</tr>
<tr>
<td><strong> Activation </strong></td>
<td> enabled</td>
</tr>
<tr>
<td><strong> Log </strong></td>
<td> all</td>
</tr>
<tr>
<td><strong> Early upload </strong></td>
<td> 50 megabytes</td>
</tr>
<tr>
<td><strong> Periodic upload </strong></td>
<td> 24 hrs 0 minutes</td>
</tr>
<tr>
<td colspan='2'> Primary FTP Server </td>
</tr>
<tr>
<td><strong> Host </strong></td>
<td> </td>
</tr>
<tr>
<td><strong> Port </strong></td>
<td> 21</td>
</tr>
<tr>
<td><strong> Path </strong></td>
<td> </td>
</tr>
<tr>
<td colspan='2'> Alternate FTP Server </td>
</tr>
<tr>
<td><strong> Host </strong></td>
<td> </td>
</tr>
<tr>
<td><strong> Port </strong></td>
<td> 21</td>
</tr>
<tr>
<td><strong> Path </strong></td>
<td> </td>
</tr>
<tr>
<td colspan='2'> List of Selected Categories and Actions</td>
</tr>
<tr>
<td colspan='2'>Locations</td>
</tr>
<tr>
<td><strong> Webfilter </strong></td>
<td> Enabled</td>
</tr>
<tr>
<td colspan='2'> Locations List</td>
</tr>
</table>
</td>
</tr>
</table>
<p>
</body>
</html>
I call the following method in my C# code:
public void createPdf(string html, string dest)
{
HtmlConverter.ConvertToPdf(html, new FileStream(dest, FileMode.Create));
}
The converted PDF ignores most of the CSS directives. I tried this on iText's online converter and get the same results.
The HTML looks like this:
The converted PDF looks like this:
Any ideas why this is happening and what I can do to fix? Thanks!

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.

Generate pdf using iTextSharp for different languages

I have tried different options, but it did not work. The code generated pdf for English but does not work for other languages.
using (var ms = new MemoryStream())
{
// Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF
var doc = new Document();
{
// Create a writer that's bound to our PDF abstraction and our stream
var writer = PdfWriter.GetInstance(doc, ms);
{
// Open the document for writing
doc.Open();
string finalHtml = string.Empty;
// Read your html by database or file here and store it into finalHtml e.g. a string
// XMLWorker also reads from a TextReader and not directly from a string
using (var srHtml = new StringReader(sHtmlText))
{
// Parse the HTML
iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml);
}
doc.Close();
}
}
// After all of the PDF "stuff" above is done and closed but **before** we
// close the MemoryStream, grab all of the active bytes from the stream
return new PDFFormFillerResult(ms, PDFFormFillerResultType.Success, string.Empty);
//bytes = ms.ToArray();
}
Well we had to buy another 3rd party tool which understands UNICODE characters.
I was able to create multi language PDF in English and Japanese.
The prerequisite for achieving this
1. To have appropriate Font which supports the languages you are planning to use.
2. Implement IFontProvider interface from iTextSharp and register the multi language font you will be using.
If you follow these 2 steps, you can create multi language PDF.
Code Sample:
public class smartUIFontProvider: IFontProvider
{
public Font GetFont(string fontname, string encoding, bool embedded, float size, int style, BaseColor color)
{
string myFont = #"C:\Tasks\Projects\SampleProject\iTextDemo_PDF\SmartFontUI\SmartFontUI.otf";
iTextSharp.text.pdf.BaseFont bfR;
bfR = iTextSharp.text.pdf.BaseFont.CreateFont(myFont,
iTextSharp.text.pdf.BaseFont.IDENTITY_H,
iTextSharp.text.pdf.BaseFont.EMBEDDED);
iTextSharp.text.BaseColor clrBlack =
new iTextSharp.text.BaseColor(0, 0, 0);
iTextSharp.text.Font fntHead =
new iTextSharp.text.Font(bfR, 12, iTextSharp.text.Font.NORMAL, clrBlack);
return fntHead;
}
public bool IsRegistered(string fontname)
{
return true;
}
}
static void Main (string[] args)
{
// step 1
Document document = new Document();
Byte[] bytes;
var fileName = "resources\\test_" + System.DateTime.Now.ToString("ddMMyyyy_hhmm") + ".pdf";
var testFile = Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), fileName);
MemoryStream ms = new MemoryStream();
// step 2
using (var writer = PdfWriter.GetInstance(document, ms))
{
document.Open();
String example_html = #" <!DOCTYPE html> <html> <head> </head> <body> <h1>Change of Control Application</h1> <br/> <p>Please fill out this form if there are updates to your current organization and its relationship Company has on file with the legal binding entity. Company will review the information and may ask you to provide further information before Company agrees to the requested changes.</p> <br/> <table class='bodyText1LIC general' style='width:700px' id='tblInputForm' > <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3>Licensee Information</h3> </td> </tr> <tr> <td class='bodyText1SerNo'>1.</td> <td class='bodyText1LIC'>Licensee Name </td> <td valign='top' class='txtboxtd'> 字詰めなどの調整をおすすめします </td> <td> </td> </tr> <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3>Licensee Primary Contact Information </h3> </td> </tr> <tr> <td class='bodyText1SerNo'>2.</td> <td class='bodyText1LIC'>Name</td> <td class='txtboxtd'> めなどの調整 </td> <td> </td> </tr> <tr> <td class='bodyText1SerNo'>3.</td> <td class='bodyText1LIC'>Job Title</td> <td class='txtboxtd'> T</td> <td> </td> </tr> <tr> <td class='bodyText1SerNo'>4.</td> <td class='bodyText1LIC'>Mailing Address</td> <td class='txtboxtd'>めなどの調整</td> <td> </td> </tr> <tr> <td class='bodyText1SerNo'>5.</td> <td class='bodyText1LIC'>Telephone Number </td> <td class='txtboxtd'>T</td> <td> </td> </tr> <tr> <td class='bodyText1SerNo'>6.</td> <td class='bodyText1LIC'>Email Address </td> <td class='txtboxtd'>abc#test.com</td> <td> </td> </tr> <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3> Organizational Structure</h3> </td> </tr> <tr> <td class='bodyText1SerNo'> 7.</td> <td class='bodyText1LIC' colspan='3'> Will your Company's Name Change? </td> </tr> <tr> <td></td> <td colspan='3'> Yes</td> </tr> <tr class='nc' id='TrCompanyName'> <td></td> <td class='bodyText1LIC' colspan='2'> a) New company name </td> <td class='txtboxtd'> DSFDASFASDFDSA</td> </tr> <tr class='nc' id='TrEffectiveDate'> <td></td> <td class='bodyText1LIC' colspan='2'> b) Effective Date Company change will take place </td> <td class='txtboxtd'> 04/20/2017</td> </tr> <tr> <td class='bodyText1SerNo'>8.</td> <td class='bodyText1LIC' colspan='3'>Has your Company been Reincorporated or under gone an Internal Reorganization? </td> </tr> <tr> <td></td> <td colspan='3'> No</td> </tr> <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3>Assets / Stocks to be Acquired </h3> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3>Assets to be Acquired</h3> </td> </tr> <tr> <td class='bodyText1SerNo'>9.</td> <td class='bodyText1LIC' colspan='3'>Will some or all of your Company’s Assets be Acquired? </td> </tr> <tr> <td></td> <td colspan='3'> No</td> </tr> <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3>Stocks to be Acquired </h3> </td> </tr> <tr> <td class='bodyText1SerNo'>10.</td> <td class='bodyText1LIC' colspan='3'>Will some or all of your Company’s Assets be Acquired? </td> </tr> <tr> <td></td> <td colspan='3'> No</td> </tr> <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3> Effects of Change to Licensee</h3> </td> </tr> <tr> <td class='bodyText1SerNo'> 11.</td> <td class='bodyText1LIC' colspan='3'> Please indicate which Company is the Surviving Legal Entity? </td> </tr> <tr> <td></td> <td class='txtboxtd' colspan='3'> T</td> </tr> <tr> <td class='bodyText1SerNo'>12.</td> <td class='bodyText1LIC' colspan='3'>Please provide the Company that will be the Licensee? </td> </tr> <tr> <td class='txtboxtd'> </td> <td colspan='3'> T</td> </tr> <tr> <td valign='top' class='bodyText1SerNo'>13.</td> <td class='bodyText1LIC' colspan='3'>Will any companies exist to operate as separate Subsidiaries or Affiliates ? </td> </tr> <tr> <td></td> <td colspan='3'> No</td> </tr> <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3>Existing Agreements</h3> </td> </tr> <tr> <td class='bodyText1SerNo'>14.</td> <td class='bodyText1LIC' colspan='3'>Please identify if any Licenses that will be affected by the Changes described above </td> </tr> <tr> <td></td> <td colspan='3'> No</td> </tr> <tr> <td class='bodyText1LIC' colspan='4'> </td> </tr> <tr> <td class='tableBody1' colspan='4'> <h3>Corporate Documentation</h3> </td> </tr> <tr> <td valign='top' class='bodyText1SerNo'>15.</td> <td class='bodyText1LIC' colspan='3'>Please Select from 1 of the 2 options listed below</td> </tr> <tr> <td></td> <td colspan='3'> Please Describe the Full Legal Structure of this Organization Change in relation to Licensing.</td> </tr> <tr> <td></td> <td colspan='3'> ASDFSDAFDSAFADSFDASF </td> </tr> </table> </body> </html>";
String example_css = #"html { font-family: SmartFontUI; font-size: 14px; } h1, h2, strong { font-family: SmartFontUI; font-weight: bold; display: inline; } h1 { font-size: 18pt; } .main { font-size: 12pt; color: black; font-family: SmartFontUI, Arial, Sans-Serif; background-color: white; text-align: left; line-height: 1.4em; margin: 2%; } .mainDesc { width: 100%; margin: 10px 0; } span { float: left; display: block; width: 100%; margin-bottom: 5px; } .bodyText1SerNo { width: 2em; } .bodyText1LIC { width: 22em; } .txtboxspan { width: 32em; } .tableBody1 { width: 100%; } .nc { margin-left: 100px; } .subtitle { font-size: 16pt; }";
FontFactory.Register(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "SmartFontUI.otf"), "SmartFontUI");
XMLWorkerHelper worker = XMLWorkerHelper.GetInstance();
MemoryStream msHtml = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_html));
MemoryStream msCss = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(example_css));
smartUIFontProvider smartUIFontObj = new smartUIFontProvider();
worker.ParseXHtml(writer, document, msHtml, msCss, System.Text.Encoding.UTF8, smartUIFontObj);
// step 5
document.Close();
}
bytes = ms.ToArray();
System.IO.File.WriteAllBytes(testFile, bytes);
}

Xpath select all tr without table with id=x

Hello i need to select all tr,but in some tr i have a table with id=WHITE_BANKTABLE.
I need to select only Tr that dont't have this table with id.
My html
<table id=mytable_body>
<TR id=TR_ROW_BANKTABLE class=TR_ROW_BANKTABLE style="BACKGROUND-COLOR: #f6f8fa" align=right bgColor=#f6f8fa>
<TD noWrap align=right w_idth="190"> </TD>
<TD align=right>010073/15922</TD>
</TR>
> **//This Tr with TABLE id=WHITE_BANKTABLE i don't need**
<TR>
<TD colSpan=8 align=center>
<TABLE id=WHITE_BANKTABLE cellSpacing=0 borderColorDark=#edf0f5 cellPadding=3 width="100%" bgColor=white borderColorLight=#edf0f5 border=1 isWhiteTable="Y">
<TBODY>
<TR class=TR_BANKTABLE align=right vAlign=top>
<TD> sdfsd </TD>
<TD>sdfs</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR id=TR_ROW_BANKTABLE class=TR_ROW_BANKTABLE style="BACKGROUND-COLOR: #f6f8fa" align=right bgColor=#f6f8fa>
<TD noWrap align=right w_idth="190"> </TD>
<TD align=right>010073/15922</TD>
</TR>
</table>
Thanx.
Assuming the above is correctly formatted as XML (insert missing double quotes):
var q =
xml.XPathSelectElements(#"/tr[not(descendant::table[#id = 'WHITE_BANKTABLE'])]");

How To select record using Xpath in Selenium

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

Categories