是“启用”吗?方法可用于Watir和/或页面对象的链接? [英] Is "enabled?" method available on Watir and/or Page-Objects for a link?

查看:161
本文介绍了是“启用”吗?方法可用于Watir和/或页面对象的链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我正在确定这个链接是否启用,等待启用,以点击它。我使用Cucumber + Ruby + Watir +页面对象宝石。链接非常类似于:

Yesterday i was working on determining is this link was or not enabled, waiting until enabled in order to click it. I'm using Cucumber + Ruby + Watir + Page-Object gem. The link is very similar to:

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

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

Once you fill some fields, the link is enabled and the source changes to:

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

想法是等到链接以这种方式启用, p>

The idea is to wait until the link is enabled in this way, which works with buttons:

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

...链接。我使它工作确定属性是否存在,这样:

...but does not work with the link. I made it work determining if the attribute exists, this way:

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 here ,似乎可用于所有元素。但在 Watir文档中找到相同的方法,似乎只有可用于按钮,选择和输入。

Looking for the "enabled?" method at the Watir documentation here or at the Page-Object gem here, it seems that is available for all elements. But looking for the same method in the Watir documentation here, seems it's only available for Buttons, Selects and Inputs.

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

So, i wonder is there is an "enabled?" method for links (anchors) and, if it exists, how to use it. Can you help clarify this issue, please? Thank you very much!

推荐答案

Watir-webdriver不支持启用? 。我相信这是因为 disabled 属性不是链接的标准属性。

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.

另一方面,Watir -classic支持链接的启用?方法。但是,它总是返回 false (再次因为链接无法禁用)。

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?).

应尽量避免在可能的情况下直接使用Watir-webdriver。页面对象gem有自己的方法用于等待和获取属性值:

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

这篇关于是“启用”吗?方法可用于Watir和/或页面对象的链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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