Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

2 like 0 dislike
308 views
by Contributing Tester (82 points)
retagged by
How can I check/validate if html of table is OK with selenium C# ?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
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 Contributing Tester (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 The go-to Tester (181 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 Contributing Tester (82 points)
Can you tell me please reference for HTML ?

HTMLDocument doc = new HTMLDocument();
by The go-to Tester (181 points)
You can try using

System.Windows.Forms

Hope that helps.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...