0

昨天我正在努力确定这个链接是否启用,等到启用才能点击它。我正在使用 Cucumber + Ruby + Watir + Page-Object gem。该链接非常类似于:

<a id="the_link"  href="#" disabled="disabled">Proceed with your order</a>

填写一些字段后,链接将启用并且源更改为:

<a id="the_link"  href="#">Proceed with your order</a>

这个想法是等到以这种方式启用链接,这适用于按钮:

def click_on_link
  Watir::Wait.until { self.the_link_element.element.enabled? }
  self.the_link
end

...但不适用于链接。我通过这种方式确定属性是否存在:

def click_on_proceed_form
  Watir::Wait.until { !self.the_link_element.element.attribute_value('disabled') }
  self.proceed_form_submit
end

寻找“启用?” 此处的Watir 文档或此处的Page-Object gem中的方法,似乎适用于所有元素。但是在此处的 Watir 文档中寻找相同的方法,似乎它仅适用于按钮、选择和输入。

所以,我想知道是否有“启用”?链接(锚点)的方法,如果存在,如何使用它。你能帮忙澄清一下这个问题吗?非常感谢!

4

1 回答 1

4

Watir-webdriver does not support the enabled? method for links. I believe this is because the disabled attribute is not a standard attribute for links.

On the other hand, Watir-classic does support the enabled? method for links. However, it will always return false (again because links cannot be disabled).

Therefore, I think your approach is correct (unless you want to monkey patch the link elements to support the enabled?).

However, you should try to avoid using Watir-webdriver directly where possible. The page-object gem has its own methods for waiting and getting attribute values:

def click_on_proceed_form
  wait_until{ !the_link_element.attribute('disabled') }
  proceed_form_submit
end
于 2014-01-02T17:40:29.740 回答