2

After reading a lot of code examples I tried to find the <tr> elements where the content of the descendant <span> element matches the parameter columnValue and I only want to search in the column with the index given in columnId. I tried something like this in with Selenium in Java, but I always get an InvalidSelectorException: Xpath expression cannot be evaluated. I tested both conditions individually in this Xpath expression and they work without any problem. But when I combine them with the and operator in one single XPath Expression, the Exception is thrown.

This is my Java code:

public WebElement getRow(final String columnId, final String columnValue) {
      final List<WebElement> eleList =
             getElement().findElements(
                   By.xpath("tbody/tr[td/span/text()='" + columnValue + "' and ./td/position()=" + (columnId + 1)"]"));
      return null;
}

This is the corresponding HTML Code:

<tbody>
  <tr class="even">
    <td>
      <span>Regionalmarkt Nord</span>
    </td>
    <td>
      <span>777</span>
    </td>
    <td>
      <span id="links">        
        <a name="delete_button" href="#" > <img title="Delete" src="/path/..."/></a>
        <a id="edit_button" href="#"> <img title="Edit" src="/path/..."/></a>  
       </span>
    </td>
  </tr>
  <tr>
  ...
  </tr>
</tbody>

2 Answers 2

2

try this xpath expression:

"//td[" + (columnId + 1) + "]/span[text()='"+ columnValue +"']/ancestor::tr[1]"
Sign up to request clarification or add additional context in comments.

Comments

0

You can use firebug to get xPath for the element .

Refer this article :

http://www.wikihow.com/Find-XPath-Using-Firebug

Check this link for similar question :

How to get the absolute XPath for an element within Firebug?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.