'Q: Looping through table elements and identifying through CSS styles (selenium webdriver in c#)

I have a table with elements that have no value, but different styles. I need to loop through them and select the first cell with no style whatsoever. How can I go about this?

I tried with using CSS selectors but to no avail because I couldn't find other possibilities. The class for all elements is the same. The unique identifier I found were the ones called 'startdate' but that needs hard-coding (which I don't plan on using in the long run).

Sharing below the code I have:

var elemTable = driver.FindElement(By.Xpath(".//*[@id='gantt']//*[@id='rhtblock']//*[@id='gridrhtbot']));
List<IWebElement> lstTrElem = new List<IWebElement>(elemTable.FindElements(By.TagName("tr")));
foreach(var elemTr in lstTrElem)
{
List<IWebElement> lstTdElem = new List<IwebElement>(elemTr.FindElements(By.TagName("td")));
if(lstTdElem.Count>0)
{
foreach (IWebElement elemTd in lstTdElem)
{ //nothing at this point//
}

This is where I'm stuck right now and can't progress any further.

HTML code below:

enter image description here

Also showing a sample of how the table looks:

00 01 02 03 04 05
Delivery
Area 1 (red line top border) (filled grey cell) (filled green cell) (filled green cell) (filled green cell) (filled green cell)
Area 2 (filled green cell) (filled green cell) (filled green cell) (red line top border) (red line top border) (filled green cell)
Area 3 (filled grey cell) (filled grey cell) (filled grey cell) (red line top border) (red line top border) (filled grey cell)

Hoping for any feedback or answers. Fingers crossed the details, codes, and tables can be of help too.



Solution 1:[1]

You can iterate through all cells row by row (see Iterate through 2 dimensional array c#).

Rows and columns count is easy to get with FindElements(..).Count().

And to access the specific cell - use XPath with indexes like //table/tbody/tr[1]/td[1].

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shatulsky