power_settings_new

Check/validate HTML of table

by (82 points)
+2 votes
112 views
How can I check/validate if html of table is OK with selenium C# ?

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
0 votes
Table has Table Rows and Table Data.

You can first get <table> element and get all rows by

WebElement tableElement =  driver.findElement(By.id("Your selector here"));

List<WebElement> rows = tableElement.findElement(By.tagName("tr"));

List<WebElement> rowData = rows.get(0).findElement(By.tagName("td")); //getting table data of the first row.

 

Hope above sudo code helps.
by (82 points)
int hCount = ObjectRepository.Driver.FindElement(By.XPath("//div[@data-widget='widgets.livetable']")).Size.Height;
            int wCount = ObjectRepository.Driver.FindElement(By.XPath("//div[@data-widget='widgets.livetable']")).Size.Width;

But if structure of html is not good what I will get ? I must check structure of html of table is someone forgot tr or td ... ?
by (171 points)
Usually browsers like chrome and firefox will take care of this. In case of you want to check HTML structure, you will have to first get HTML source using

String html = driver.getPageSource();

HtmlDocument doc = new HtmlDocument();

doc.LoadHtml(html);

if (doc.ParseErrors.Count() > 0)
{
   //Invalid HTML
}
by (82 points)
Can you tell me please reference for HTML ?

HTMLDocument doc = new HTMLDocument();
by (171 points)
You can try using

System.Windows.Forms

Hope that helps.
add
...