IE7 中禁用输入的 XPath 表达式.用硒测试 [英] XPath expression for disabled input in IE7. Testing with Selenium

查看:16
本文介绍了IE7 中禁用输入的 XPath 表达式.用硒测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题很简单.我正在编写一个必须与 IE7 一起使用的 Selenium 测试.我有一个包含几行和 3 列的 HTML 表格:

My problem is very simple. I'm writing a Selenium test that MUST work with IE7. I have a HTML table with couple of rows and 3 columns:

第 1 列 - 包含一个复选框

Column 1 - contains a check box

第 2 列 - 包含链接

Column 2 - contains a link

第 3 列 - 包含一些自由文本

Column 3 - contains some free text

表格中的一个(并且只有一个)复选框被禁用.我的任务是找到并单击禁用复选框旁边的链接(在禁用复选框的行上).在 FireFox 中,这个简单的 XPath 表达式工作正常:

One (and ONLY one) of the checkboxes in the table is disabled. My task is to locate and click the link next to the disabled checkbox (on the row of the disabled checkbox). In FireFox this simple XPath expressions work fine:

//tr/td/input[@disabled]/../../td[2]/a

//tr/td/input[@disabled='disabled']/../../td[2]/a

但在 IE7 中,无论复选框是否启用,第一个表达式都会单击顶行,而第二个表达式不起作用.

But in IE7 the first expression clicks the top row no matter if the checkbox is enabled or disabled and the second one does not work.

由于 HTML 文档很长,我将重要的部分放在下面(如 FF 所示):

Since the HTML document is very long I'm putting the important part below (as shown in FF):

<tr>
    <td class="table_detail w e s center">
        <input name="Delete_kG0KCgAMniwAAAEsxxgeUH0G" type="checkbox">
    </td>
    <td class="table_detail e s">
        <a href="..." class="table_detail_link">000000</a>
    </td>
    <td class="table_detail e s">
        some text
    </td>
</tr>

<tr>
    <td class="table_detail w e s center">
        <input name="Delete_hooKCgAMi5AAAAEsFnQeUH0G" type="checkbox">
    </td>
    <td class="table_detail e s">
        <a href="..." class="table_detail_link">111111</a>
    </td>
    <td class="table_detail e s">
          &nbsp;
    </td>
</tr>

<tr>
    <td class="table_detail w e s center">
        <input disabled="disabled" type="checkbox">
    </td>
    <td class="table_detail e s">
        <a href="..." class="table_detail_link">400086</a>
    </td>
    <td class="table_detail e s">
        &nbsp;
    </td>
</tr>

应该点击最后一个链接:

The last link should be clicked:

<a href="..." class="table_detail_link">400086</a>

我们在 JUnit 3 测试中使用 Java Selenium API.测试是这样的:

We use the Java Selenium API in JUnit 3 tests. The test is something like:

public void testSomething()
{
   ...
   selenium.click("//tr/td/input[@disabled]/../../td[2]/a");

   //wait to load and then test something on the page that is opened.
   ...
}

这在 FF 中有效,但在 IE7 中无效.在 IE7 中,它单击第一行上的链接,就好像禁用被忽略一样.它也在 XPather(FF 插件)中评估正确.

This works in FF but not in IE7. In IE7 it clicks the link on the first row as if disabled is ignored. It also evaluates correct in XPather (FF plugin).

非常感谢您的帮助.

谢谢!

推荐答案

据记录,我能够通过使用 DOM 定位器解决问题.不幸的是,它看起来很丑:

For the record I was able to resolve the problem by using a DOM locator. Unfortunately it looks as ugly as:

dom=function getLinkNextToDisabled() 
{
    var addressesTable = document.getElementsByName('AddressList')[0].getElementsByTagName('table')[0].getElementsByTagName('table')[0];
    var inputs = addressesTable.getElementsByTagName('input');
    for (i = 0; i < inputs.length; i++)
    {
        if (inputs[i].disabled) 
        {
            return inputs[i].parentNode.parentNode.getElementsByTagName('a')[0];
        }
    }
};
getLinkNextToDisabled();

不幸的是,这样的代码让我很难过,所以我仍然愿意接受任何可以在 IE7 中运行的 XPath 解决方案.

Unfortunately code like this makes me sad, so I'm still open for any XPath solution that will work in IE7.

问候!

这篇关于IE7 中禁用输入的 XPath 表达式.用硒测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆