sam
sam

Reputation: 4684

How to use counter in xpath

I am using the following code to get the id of a row that is randomly generated:

string[] rowIds = new string[numofRowsPassengerTable];
for (int counter=1; counter < numofRowsPassengerTable; counter++)
{
    rowIds[counter] = browser.GetAttribute("xpath=//table[@id='tblPassengers']/tbody/tr[counter]@id");
}

But the above is not returning anything. If I use 1 or 2 instead of counter it returns the id. Any idea how can I use that counter to get row ids?

Upvotes: 0

Views: 254

Answers (1)

creinig
creinig

Reputation: 1580

Looks like you wanted to actually use "counter" as a variable in the xpath string:

browser.GetAttribute("xpath=//table[@id='tblPassengers']/tbody/tr[" + counter + "]@id");

As it stands now, you tell the XPath engine to use some "counter" HTML element as index to the TRs, which obviously won't work.

Upvotes: 1

Related Questions