简体   繁体   English

watir goto 方法作为参数

[英]watir goto method as param

I have the following code:我有以下代码:

class Test
  def initialize(browser)
    @browser = browser
  end

  def init
    @browser.element(css: ".app").wait_until(&:present?)
  end
end

Run like this:像这样运行:

browser = Watir::Browser.new(:chrome, headless: true)
test = Teste.new(browser.goto('https://www.google.com))
teste.init

And I got this error:我得到了这个错误:

undefined method `element' for #String:0x00007fe29d10f978 (NoMethodError) #String:0x00007fe29d10f978 (NoMethodError) 的未定义方法“元素”

It seems that passing the goto method as a parameter doesn't work.似乎将 goto 方法作为参数传递是行不通的。 How can I solve that?我该如何解决?

The following code will work以下代码将起作用

class Test
def initialize(browser)
  @browser = browser
end

 def init
   @browser.goto("https://www.google.com")
   @browser.element(css: ".app").wait_until(&:present?)
 end
end


browser = Watir::Browser.new(:chrome, headless: true)
test = Test.new(browser)
test.init()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM