簡體   English   中英

如何使用ruby-watir-cucumber和頁面對象單擊滑塊中的任何位置?

[英]How to click at any position in a slider using ruby-watir-cucumber and page object?

我正在使用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定義了Page對象:

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

然后,我可以在相應的步驟中使用它:

page.slider_amount_element.click

關於cheezy頁面對象的參考: https ://www.rubydoc.info/github/cheezy/page-object/PageObject/Accessors#div-instance_method

以這種方式使用它,我可以單擊滑塊的中間,這沒關系。 但是,如何在滑塊的任何位置單擊?

您將需要使用Selenium的#move_to特別是#move_to方法。 不幸的是,Watir以及因此的Page-Object尚未圍繞動作構建包裝( 功能請求#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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM