Q:

Using Watir to click a table element

JavaScript button I'd like to click although it's in a table:
<table>
  <tr>
    <td height="20" align="center" nowrap style="color:#0000FF; cursor:pointer; border: 1 solid #426996; background-color: #FAFAFF;" 
      onClick="Initial();"
      onMouseOver="javascript:{style.backgroundColor='#426996'; style.color='#FFFFFF'}" 
      onMouseOut="javascript:{style.backgroundColor='#FFFFFF'; style.color='#0000FF'}">
      <font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>&nbsp;New Incident&nbsp;</b></font>
    </td>
    <td width="4"></td>

There are four more "buttons" here but I'm unable to click any of them. It seem the only thing that sepearate the buttons from on another is  the onClick javascript event. I've tried using xpath but i just cant seem to find the element. I've tried this...
ie.button(:xpath => "//td[@onClick='Initial();']".exists?

ie.link(:xpath => "//td[@onClick='Initial();']".exists?

and they return false.
I think once this element is found i can just use the .fire_event('onClick') or .click and it should work i just can't seem to find it.

A:

Use #td method with a regexp instead:
ie.td(:html => %r{Initial()}).click

If it's possible then assign some html ID or class attribute to your td to make the locating easier. Something in the lines of:
<td id="mytd" ... onClick="Initial();">...</td>
ie.td(:id => "mytd").click

Or use text with a regexp:
ie.td(:text => /New Incident/).click

A:

The element you are trying to click is not a button but a cell in a table. More information: http://www.w3.org/wiki/HTML/Elements/td
Something like this should work (not tested):
browser.element(:css => "td[onClick=Initial();]").click

More information: http://www.w3.org/TR/CSS2/selector.html#matching-attrs

