简体   繁体   中英

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)

It seems that passing the goto method as a parameter doesn't work. 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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