R.R
R.R

Reputation: 23

Selenium, find element by <td>

I'm pretty new to test automation and right now I'm trying to figure out what is the best way to find an element by <td> text , in my case "Man pdr". I will attach a picture. Basically my goal is to click this element, by <td> text, not by class because there are lots of classes with the same name. I don't really want to use direct xpath in order to make it more dynamic (to find it even if it changes locations). Is there any way to do it? I'm using Selenium + Java. enter image description here

Code:

login.getDriver().findElement(By.xpath("//*[@id='outlet30all‌​']/table/tbody/tr[co‌​ntains(text(), 'Man pdr')]"));

Upvotes: 0

Views: 5912

Answers (1)

Andersson
Andersson

Reputation: 52665

You should avoid including tbody tag in your XPath. Try below code:

login.getDriver().findElement(By.xpath("//td[text()='Man pdr']"));

Upvotes: 2

Related Questions