Reputation: 761
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
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