<tr> invisibile

I would like to count the lines of a grid. I have uniquely identified 3 rows with an xpath but the count gives me 4 because an invisible one is generated even if it has different attributes. Is there any way to eliminate the from the count?

WebDriver driver = DriverFactory.getWebDriver()
WebElement TableVoci = driver.findElement(By.xpath(…))
List Rows = TableVoci.findElements(By.xpath(…))

rows_int = Rows.size()

Is this what you want?

rows_int = Rows.size() - 1
1 Like

Please show the XPath expression here.

Please show how the HTML source with the “attributes” looks like.

Can you tell us how the invisible <tr> element is made invisible?

You should read the HTML source.

Possibly with some CSS styling.

You should take that into account in the locator (CSS Selector or XPath expression) and exclude the invisible <tr> element.

This class:

class=“dx-row dx-freespace-row dx-state-invisible”

is also considered with the following xpath

WebDriver driver = DriverFactory.getWebDriver()
WebElement TableVoci = driver.findElement(By.xpath(‘(//wki-grid//tbody)[2]//tr[@class=“dx-row dx-data-row”]’))
List Rows = TableVoci.findElements(By.xpath(‘(//wki-grid//tbody)[2]//tr[@class=“dx-row dx-data-row”]’))

I solved with:

rows_int = Rows.size() - 1

This statement assumes that you will always have 1 invisible row. Is it really the case?

Isn’t it the case that you have 2 or more (variable number of) invisible rows, or you have zero invisible row?

Just a small advice.

    ...      //tr[contains(@class,"dx-row") and contains(@class, "dx-data-row")]

would be better.

Why? — The following 2 lines of HTML has the same meaning in terms of HTML+CSS semantics.


 .... <tr class="dx-row dx-data-row">


 .... <tr class="dx-data-row dx-row">

However the xpath //tr[@class="dx-row dx-data-row"] will match the case (1) only. It does not match the case(2).

The xpath //tr[contains(@class,"dx-row") and contains(@class, "dx-data-row")] will match both of (1) and (2)

An XPath

//tr[contains(@class, "data-row") and not(contains(@class, "dx-state-invisible"))]

would select the <tr> elements with data-row class and WITHOUT dx-state-invisible class. I guess, this is what you wanted.

1 Like

Yes, only one invisible row.

Thanks for your advice.

When you have a minute please be sure to mark the response that helped solve your question so we can close this thread.
Thank you for your participation.