user3292642
user3292642

Reputation: 761

How to find tablerow element containing a certain span element with Selenium Webdriver

I'm trying to write a method which takes a string variable (the name of a certain node) and gets the tr element containing an element with text same as the given string.

First step would be to find an element in my html with

element.text = string

But i cant get the the XPath expression for that.

I tried

  driver.FindElement(By.XPath(String.Format("//span[text()={0}]", &stringVariable)));

This code throws an exception "cannot be evaluated or does not result in a Webelement."

Thanks in advance

EDIT:

neither

//tr[span[text()= 'variableValue']] 

nor

//tr[span[contains(text(), 'variableValue')]]

works whereas

//tr[contains(text(), 'partOfVariableValueUntilFirstSpace')]

will work. I cannot explain why...

Upvotes: 1

Views: 829

Answers (1)

Ajinkya
Ajinkya

Reputation: 22730

You can use following Xpath

//tr[span[text()='variableValue']]

It will find tr element which have a span element with text as variable value.

Upvotes: 1

Related Questions