是否“启用?"Watir 和/或 Page-Objects 上可用的链接方法? [英] Is "enabled?" method available on Watir and/or Page-Objects for a link?

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

问题描述

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

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>

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

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 documentation herePage-Object gem here,似乎适用于所有元素.但是在 Watir documentation here 中寻找相同的方法,似乎只有可用于按钮、选择和输入.

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 不支持链接的enabled? 方法.我相信这是因为 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 确实支持链接的 enabled? 方法.但是,它总是会返回 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.page-object 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 和/或 Page-Objects 上可用的链接方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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