1
<table id="versionId" class="displayTable" cellspacing="0" cellpadding="0" rules="groups" style="width:100%;border-right:1px solid #DFDFDF;border-left:1px solid #DFDFDF;">
<caption class="displayCaption">
<thead>
<tbody>
<tr class="rowOdd">
<td style="width:1%">
<td style="width:15%;">
<span class="font">1</span>
</td>
<td style="width:12%">
<td style="width:10%">
<td style="width:10%">
<td style="width:13%">
<td style="width:18%">
=======

any way i can get that 1 and print out?

i tried out this .//*[@id='versionId']/tbody/tr/td[2]/span/text():

System.out.println(driver.findElement(By.xpath(".//*[@id='versionId']/tbody/tr/td[2]/span/text()")));

it return me with error:

The given selector .//[@id='versionId']/tbody/tr/td[2]/span/text() is either invalid or does not result in a WebElement. The following error occurred: InvalidSelectorError: The result of the xpath expression ".//[@id='versionId']/tbody/tr/td[2]/span/text()" is: [object XrayWrapper [object Text]]. It should be an element.

HELP D:

1
  • 1
    Maybe you should remove dot "." before //* Commented Dec 4, 2013 at 10:04

1 Answer 1

4

In your xpath you are getting the text, not the element. To find the element you can use the following xpath: //span[@class='font']

If you need to print out the text then the code should be following:

System.out.println(driver.findElement(By.xpath("//span[@class='font']")).getText())
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks you for the help! this is the one im looking for!

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.