【问题标题】:How to click at any position in a slider using ruby-watir-cucumber and page object?如何使用 ruby​​-watir-cucumber 和页面对象单击滑块中的任何位置?
【发布时间】:2019-01-29 14:11:45
【问题描述】:

我正在使用 Ruby+Watir+Cucumber+Watir+CeezyPO+.... 在一个测试中我有下一个 div 元素:

<div class="slider-importe ui-slider ui-corner-all ui-slider-horizontal ui-widget ui-widget-content"><div class="ui-slider-range ui-corner-all ui-widget-header ui-slider-range-min" style="width: 50.3384%;"></div><span tabindex="0" class="ui-slider-handle ui-corner-all ui-state-default" style="left: 50.3384%;"></span></div>

Wich 只是一个数量滑块。

在我的测试中,我想单击滑块的任何位置并检查字段文本中显示的金额结果。

我已经为 div 定义了页面对象:

div(:slider_amount, :xpath => '//*[@id="simulatorParent"]/div[1]/div[1]/div[1]')

然后我可以在相应的步骤中使用它:

page.slider_amount_element.click

关于 cheezy Page Object 的参考:https://www.rubydoc.info/github/cheezy/page-object/PageObject/Accessors#div-instance_method

以这种方式使用它,我可以单击滑块的中间,这没关系。但是,怎么可能点击滑块的任意位置呢?

【问题讨论】:

    标签: ruby cucumber watir


    【解决方案1】:

    您将需要使用 Selenium 的 ActionBuilder - 特别是 #move_to 方法。不幸的是,Watir 和 Page-Object 还没有为动作构建一个包装器 (feature request #829)。

    需要的代码是:

    xoffset = 50      # how far right from the top-left corner
    yoffset = 100     # how far down from the top-left corner
    page.browser.driver.action.move_to(page.slider_amount_element.element.wd, xoffset, yoffset).click.perform
    

    page 是您的 PageObject。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-20
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 1970-01-01
      相关资源
      最近更新 更多