4

这是我正在使用的 Watir 代码:

require 'watir-classic'
browser = Watir::IE.new
browser.link(:class, "Wizardbutton").exists?

这是包含我要检查是否存在的链接的页面 HTML 的一部分。

<tr>
    <td align="left" style="vertical-align: top;">
        <a class="Wizardbutton"href="javascript:parent.showPopup('/web/wizard.html');window.focus();">
            <span>Add new Team</span>
        </a>
    </td>
</tr>

我得到的错误是:

Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_name=>["a"], :class=>"Wizardbutton"}

为什么我在 HTML 源代码中可以清楚地看到链接元素不存在的错误?我已经成功点击了页面上的其他链接,但由于某种原因我看不到这个。嵌入的跨度标签是否搞砸了?我也尝试使用 href 进行选择,但也没有用。任何见解将不胜感激!

4

2 回答 2

3

OK,谜团解开了。与 Watir 合作时,iframe 是一个主要问题。除非您专门选择 iframe,然后选择 iframe 中的项目,否则属于 iframe 的元素不可见。所以例如代码

browser.frame(:name, "nameOfFrame").link(:class, "Wizardbutton")

意味着给我一个名称属性为“nameOfFrame”的 iframe,然后选择类属性为“Wizardbutton”的链接。

于 2012-10-18T18:08:41.463 回答
2

我也面临同样的错误。有时,如果浏览器控件存在于 div 或 tables 标签中,则无法找到它。在您的情况下,链接控件放置在表格内。请试试这个

browser.table(:class=> "classname").link(:class => "Wizardbutton")

希望对你有帮助

于 2012-12-17T06:21:08.297 回答