【发布时间】:2017-09-14 10:29:35
【问题描述】:
带有 ruby 的页面对象 gem,我已经为链接定义了一些页面对象,例如:
link(:link_for_1week, text: /1 wk/)
link(:link_for_2week, text: /2 wks/)
link(:link_for_3week, text: /3 wks/)
link(:link_for_4week, text: /4 wks/)
link(:link_for_5week, text: /5 wks/)
link(:link_for_6week, text: /6 wks/)
link(:link_for_2months, text: /2 mo/)
link(:link_for_3months, text: /3 mo/)
link(:link_for_6months, text: /6 mo/)
link(:link_for_1year, text: /1 yr/)
我有一种方法可以通过用户输入动态调用这些链接:
If I give user input as '1week' it has to click on 'link_for_1week'
If I give user input as '2week' it has to click on 'link_for_2week'
and so
我不知道怎么做,我什至使用了instance_eval,但它不起作用:
def click_link(args:)
self.browser.instance_eval('link_for_'+args+'_element.click')
end
但我无法点击链接。
我不确定是否使用这个 instance_eval.. 除了 instance_eval 也是最受欢迎的...
【问题讨论】:
标签: ruby watir watir-webdriver pageobjects page-object-gem