1

I have a table within a page and the following xpath locates the element:

.//*[@id='ctools-export-ui-list-items']/tbody/tr[16]/td[4]

The page has the following html:

<table id="ctools-export-ui-list-items" class="sticky-enabled tableheader-processed sticky-table">
<thead>
<tbody>
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="blah" class="blah">
<tr id="RowInterestedIn" class="blah">
<td class="blah" title="blah">blah</td>
<td class="blah" title="blah">blah</td>
<td class="blah" title="blah">*/15 * * * *</td>
<td class="ctools-export-ui-start-time" title="Launched in thread 1 by anonymous (0)">2017-05-16 10:00:03</td>
<td class="blah" title="blah" title="no info">
<img typeof="foaf:Image" src="blah" alt=""/>
</td>
<td class="blah">Default</td>
<td class="blah">
</tr>

However when I try to get the text using getText() on the end of the locator, a blank is returned. However, it can be clearly seen that there is text: 2017-05-16 10:00:03 in the .

Any suggestions appreciated.

XpathIsAWay
  • 23
  • 1
  • 3

2 Answers2

0

Try this xpath //table[@id='ctools-export-ui-list-items']/tbody/tr/td[@class='ctools-export-ui-start-time'] and then use getText() to retrieve the text 2017-05-16 10:00:03

Let me know if this helps you.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Didn't `getText ()` retrieve the wanted text using the xpath I provided? Thanks – undetected Selenium May 17 '17 at 15:23
  • No, the get text was returning a blank. I'd normally use that. So I thought it was my selector. But both of our xpaths were selecting the same thing. After more investigation, following::text() on the end selected the text in firepath, but this caused an error in webdriver. It needed getAttribute("innerHTML"), before it would actually retrieve the text. Theres an "innerText" which might also be of use in this type of instance too. – XpathIsAWay May 18 '17 at 16:38
  • So would you like to share with us the difference between `getText` `innerHTML` & `innerText` please? Thanks – undetected Selenium May 18 '17 at 17:22
  • Not sure without reading the docs, but http://stackoverflow.com/questions/20888592/gettext-method-of-selenium-chrome-driver-sometimes-returns-an-empty-string uses it and an alternative when you get stuck. Also this part of the specs will help: https://w3c.github.io/webdriver/webdriver-spec.html#element-displayedness – XpathIsAWay May 19 '17 at 08:12
0

OK, I tried using following::text() on the end of the xpath, as this located the text in firepath. However, this resulted in an error; there is a bug but it was closed as working as expected.

Luckily one of my colleagues had come across this and I needed to use getAttribute("innerHTML") on my original xpath, rather than getText().

Hopefully this helps somebody else.

XpathIsAWay
  • 23
  • 1
  • 3