【问题标题】:How to get the html source of a page_object element?如何获取 page_object 元素的 html 源代码?
【发布时间】:2012-12-19 09:45:59
【问题描述】:

想象一下我有一个类似的 div(用 Watir 语言):

@browser.div(:id, 'home_slideshow')

我需要里面的 html 代码来做一些“神奇的正则表达式”:)。获取div html代码的方式可能是:

the_div_html = @browser.div(:id, 'home_slideshow').html

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

div(:slide_show, :id => 'home_slideshow')

要获取里面的html,我可以使用:

the_div_html = slide_show_element.html

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

*** DEPRECATION WARNING
*** You are calling a method named attribute_value at home_page.rb:80:in `get_slide_code'.
*** 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 元素获取 html 代码?正如我之前提出的一些类似问题,当然答案很简单,但我查看了 Cheezy 书、整个 stackoverflow 和页面对象 ruby​​doc 信息,但我没有找到它。你能告诉我路吗?

提前谢谢你!

【问题讨论】:

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


    【解决方案1】:

    slide_show_element.html 应该返回元素 HTML。是吗?

    弃用警告仅表示页面对象 api 尚不支持 #html 方法。你应该在这里申请:https://github.com/cheezy/page-object/issues?state=open

    【讨论】:

    • 嗨!是的,它正确返回 HTML。仅将顶部的弃用警告显示为“警告”。在现在编写代码时,我不想使用可能明天会使测试崩溃的已弃用函数。我虽然有一个页面对象方法来获取元素 HTML 源代码。我将在页面对象问题页面上请求该方法。非常感谢!
    【解决方案2】:

    作为一种临时解决方法,您可以使用 .element 直接访问 watir-webdriver 元素。

    以下内容将为您提供没有折旧警告的 html:

    slide_show_element.element.html
    

    【讨论】:

    • 它有效(正如你所有的答案......)。作为临时解决方法,它很好。我还打开了一个issue 来创建该方法,如果这样做很有趣的话。非常感谢!
    【解决方案3】:

    我将在下一个版本中将此方法添加到 gem 中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-08
      • 2018-03-14
      • 2015-09-05
      • 1970-01-01
      • 2014-05-06
      • 2020-01-22
      • 1970-01-01
      • 2013-04-06
      相关资源
      最近更新 更多