【问题标题】:How to get the attribute_value of a page_object element?如何获取 page_object 元素的属性值?
【发布时间】:2012-12-13 11:45:02
【问题描述】:

想象一下我有这样的图像:

the_image = @browser.image(:id, 'image01')

获取其类的值的方法可能是:

image_status = the_image.attribute_value('class')

好的。我正在使用 page_object gem,假设我将图像作为元素,例如:

image(:the_image, :id => 'image01')

要获取我可以使用的属性值:

image_status = the_image_element.attribute_value('class')

...但我收到了弃用警告:

*** DEPRECATION WARNING
*** You are calling a method named attribute_value at page.rb:68:in `get_status'.
*** This method does not exist in page-object so it is being passed to the driver.
*** This feature will be removed in the near future.

如何使用 page_object 元素获取 class 值?当然答案很简单,但我没有找到。你能告诉我路吗?

提前谢谢你!

【问题讨论】:

  • 该错误未显示在您的页面对象类的上下文中。也许您可以在问题中添加更多内容?
  • 嗨戴夫!没有错误,只有警告。事实上,该方法工作正常。问题是我不知道如何本地使用页面对象获取属性值。 Justin Ko 给了我答案:yourelement_element.attribute('attribute_type')

标签: ruby cucumber watir-webdriver pageobjects page-object-gem


【解决方案1】:

如果您使用最新版本的 Page-Object 和 Watir(分别为 v2.2.1 和 v6.7.3),attribute_value 将不再给出弃用警告。支持#attribute#attribute_value

对于旧版本的Page-Object,您需要使用#attribute方法:

image_status = the_image_element.attribute('class')

【讨论】:

  • 你说得对。我用谷歌搜索了 Cheezy 的书,没有找到任何东西。还查看了 Cheezy Rubydoc 信息,但似乎我没有正确搜索......下次我会三重检查;谢谢你的回答!
  • Yout 链接不幸损坏
  • 谢谢@SSchneid。我已经删除了链接。该方法不再直接在 Page-Object gem 中定义。它现在被委托给底层Watir::Element
猜你喜欢
  • 1970-01-01
  • 2020-02-22
  • 2014-08-31
  • 1970-01-01
  • 1970-01-01
  • 2021-09-17
  • 2021-08-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多