简体   繁体   中英

Does Watir-webdriver use goto method? Because url seems to open to data;

I'm new to to test automation and I'm having an issue getting started. I am using ruby 1.9.3, watir-webdriver 0.9.3, chromedirver 2.24, yosemite osx and sublime 2 / terminal to execute. I am trying to get the method 'goto' to take me to google.com, but i get this error.

rb:5:in `<main>': undefined method `goto' for nil:NilClass (NoMethodError)

this is my code

require 'rubygems'
require 'watir-webdriver'

@Browser = Watir::Browser.new :chrome #You can also use firefox
@Browserc.goto("http://google.com")

I have tried firefox and it will open to a new tab. I also tried using chrome and the browser open with "data;" in the url. I can't seem to find an answer on SO or Online. Thanks in advance for any assistance.

data; is a default string that is set in the url when the browser starts. Seems that goto method is not found. You might have a config issue.

One possible issue might be that you used @Browserc instead of @Browser when you called goto.

try

@Browser.goto("http://google.com")

Problem is c next to @Browser in your goto statement causing the issue. What I would suggest is always use something like below .It is not a best practice to use @Browser (starts with captial letter).

require 'rubygems'

require 'watir-webdriver'

browser = Watir::Browser.new :chrome #To open chrome browser

browser = Watir::Browser.new:firefox #To open Firefox browser

browser.goto "http://www.google.com"

This fix is for ubuntu:

I uninstalled the chromedriver and downloaded chrome directly from their website. The executable file should be stored in /usr/bin. Finally use the following code:

require "rubygems"
require "watir"
browser = Watir::Browser.new :chrome
browser.goto('google.com')

PS: You don't need to use watir-webdriver anymore because watir now includes it in the latest versions. That is why it is not included in this example.

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