Search code examples
rubywatirfirewatirbrowser-automationwatir-webdriver

Watir-webdriver: Firefox not clicking correct link but IE and Chrome working fine


Question help

Hi I'm new to Ruby and watir-webdriver and I've searched all over and can't find an answer to this.

I have a link that is inside a table, this table has a header on top of the table that sorts the table numerically if clicked. In Chrome and Ie, the link is clicked fine and continues on but in firefox it clicks the header and reorganizes the table, but not the link and no error message is given.

I've tried xpath, regexp, table referencing, :href, :text, (there are no id or name fields), and using the .flash method I've seen that it looks at the correct link, but still clicks the top of the table.

Here is the html

<thead>
    <tr>
        <th id="0" class="canclick" width="14%" align="left" datatype="string">
            Contract #
            <span id="sortIndicatorBlank">&nbsp;&nbsp;&nbsp;&nbsp;</span>
        </th>
    </tr>
</thead>
<tbody>
    <tr class="backD">
        <td width="10%" valign="top" align="left">
             <a href="/policy/clientAccountSummary.action?forwarder=ClientList&basho.menuNodeId=12801&basho.taskPanelNodeId=1261&number=015633828"> 015633828 </a>
        </td>

Here is the code I'm using that clicks the correct link in Chrome and Ie but not in firefox

link = "015633828"

exp1 = Regexp.new link

@browser.link(:href, exp1).click

Again to clarify: Using .flash method it finds the correct link(flashes the link I want to click inside the table), but on the actual .click operation it clicks the "Contract #" portion of the header not the link.

I think the problem might be that the table header, is a floating header, ie it moves with you as you scroll down the page and stays at the top of the page so that its always visible.

If you need more info to clarify let me know. Thanks!


Solution

  • I'm not sure why it is doing this, but as a potential workaround could you perhaps try something along the following lines to pull the href value out of the link and then have the browser goto it directly?

    @browser.goto(@browser.link(:text, ' 015633828 ').href)
    

    (you might need to add the base url for the site to the href to make that work, but you get the idea)