Find an element by text and get xpath - selenium webdriver junit


I have a table with 9 rows and 6 columns in my webpage. I want to search for a text “MakeGoodDisabled-Programwise_09_44_38_461(n)” and get the xpath of the cell. I have used the following but it fails because it is not able to find the text in the page. Can you please help? I am using Selenium Webdriver Junit to code this.

`List<WebElement> links = driver.findElements(By.tagName("td"));
Iterator<WebElement> itr = links.iterator();
String test =;
String xpath = driver.findElement("xpath");
  • You must to post comments

My intention is to find a text in a table and get the corresponding next column value in
the same row. I thought that I will replace the column number found by fetching the xpath with
the column number I want. is there a better way to do it

Of course there’s a way. Here’s one possible solution.

Get all the rows:

While (iterate over row)
While(Iterate over column)
int voila=column.Index

Now you can simply move to that particular index for the other rows; or you could use xpath like .../tr/td[voila] to retrieve all cells for that particular column.

I’ve written an approach, please don’t take to be real-working-code!

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.