views:

88

answers:

2

Hi i have this HTML code:

<tr class="odd events" style="">
<tr>
  <a title="Expand to see Actions" class="toggleEvent" name="actions_for_host_1" href="#"></a>
  <td id="7" colspan="6">
    <div>
      <ul>
        <li>Low Alarm at 2010/06/25 07:09 ( <span title="2010/06/25 14:09 (UTC)" class="time_helper">Pacific</span> )</li>
      </ul>
      <div></div>
    </div>
  </td>
</tr>

How can I retrieve the <li> value using xpath and selenium ruby, so I get back "Low Alarm at 2010/06/25 07:09 Pacific"?

I don't know what the time and date will be but I know the <li> tag will always start with Low Alarm

thanks

sorry i couldn't phrase the question better.

+2  A: 

Is there a reason why you're specifically trying to use an xpath locator for this? A CSS locator may do the job just as well, e.g.

css=li:contains('Low Alarm')
AlistairH
+3  A: 

You need to use the getText command to retrieve the text using a suitable locator. There are a few possible locators that you could use, some suggestions are listed below:

XPath:

  • locate the li based on the child span with the class time_helper

    //li[span[@class='time_helper']]
    
  • locate the li based on the text starting with 'Low Alarm'

    //li[starts-with(text(), 'Low Alarm')]
    
  • locate the li based on the text containing 'Low Alarm'

    //li[contains(text(), 'Low Alarm')]
    

CSS:

  • locate the li based on the text starting with 'Low Alarm'

    css=li:contains(^Low Alarm)
    
  • locate the li based on the text containing 'Low Alarm'

    css=li:contains(Low Alarm)
    
Dave Hunt
the trick here is the getText method. http://release.seleniumhq.org/selenium-remote-control/0.9.2/doc/java/com/thoughtworks/selenium/Selenium.html#getText(java.lang.String)
Rodreegez