ganesh kumar
ganesh kumar

Reputation: 75

Locating a table data row data without iterating

Can we locate a table row data with a simple expression like this instead of iterating through the entire table items. I am using this simple expression

driver.findElements(By.xpath("//table//tr//td[contains(text(),\"Row 1, Column 1\")])"));

for this site

String URL="http://www.tutorialspoint.com/html/html_tables.htm";
driver.navigate().to(URL);

but i am getting this error The xpath expression '//table//tr//td[contains(text(),"Row 1, Column 1")])' cannot be evaluated or does notresult in a WebElement (WARNING: The server did not provide any stacktrace information)

I know the usual realative path and ablsolute path expressions.

Upvotes: 0

Views: 127

Answers (2)

CynicalBiker
CynicalBiker

Reputation: 609

I think it maybe your syntax causing the problem try:

driver.findElements(By.xpath("//table//tr//td[contains(text(),'Row 1, Column 1')]"));

Upvotes: 1

ganesh kumar
ganesh kumar

Reputation: 75

To locate a table row based on it containing a cell with specific text you can use the following XPath locator:

 //tr[td[text()='myCellText']]

Upvotes: 1

Related Questions