0

I need to know if 1324 was Win or Loss in a table. How do I select the single <td> Element to know if it was a loss or a win.

<tr>
    <td> 1323 </td>
    <td> Won </td>
</tr>
<tr>
    <td> 1324 </td>
    <td> Loss </td>
</tr>
[...]
<tr>
    <td> 1328 </td>
    <td> Won </td>
</tr>
1
  • What do you mean by "select the single <td> Element to know if it was a loss or a win"? Commented Nov 4, 2013 at 11:40

2 Answers 2

1

Whilst the answers are correct in this question, people are forgetting the context: Selenium. You give those XPath's to it, and it'll blow up in your face.

Selenium expects XPath queries to return physical DOM elements, and not attributes from those elements.

You should find the element, and use Selenium to get it's text. This could be .getText(), or .Text or something similar in whatever language you are using (C# and Java examples below - assuming driver is a valid Driver instance):

C#:

driver.FindElement(By.XPath("//td[text()="1324"]/following-sibling::td")).Text;

Java:

driver.findElement(By.xpath("//td[text()="1324"]/following-sibling::td")).getText();
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

//td[text()='1324']/../td[2]/text()

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.