[英]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. 我正在使用ruby 1.9.3,watir-webdriver 0.9.3,chromedirver 2.24,优胜美地osx和sublime 2 /终端来执行。 I am trying to get the method 'goto' to take me to google.com, but i get this error. 我试图获取方法“ goto”将我带到google.com,但出现此错误。
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. 我已经尝试过firefox,它将打开一个新选项卡。 I also tried using chrome and the browser open with "data;" 我还尝试使用chrome,并使用“数据”打开浏览器; in the url. 在网址中。 I can't seem to find an answer on SO or Online. 我似乎找不到SO或Online的答案。 Thanks in advance for any assistance. 在此先感谢您的协助。
data; 数据; is a default string that is set in the url when the browser starts. 是浏览器启动时在url中设置的默认字符串。 Seems that goto method is not found. 似乎找不到goto方法。 You might have a config issue. 您可能遇到配置问题。
One possible issue might be that you used @Browserc instead of @Browser when you called goto. 一个可能的问题是调用goto时使用了@Browserc而不是@Browser。
try 尝试
@Browser.goto("http://google.com")
Problem is c next to @Browser
in your goto
statement causing the issue. 问题是goto
语句中@Browser
旁边的c引起了问题。 What I would suggest is always use something like below .It is not a best practice to use @Browser
(starts with captial letter). 我建议始终使用如下所示的内容。使用@Browser
(以大写字母开头)不是最佳实践。
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: 此修复程序适用于ubuntu:
I uninstalled the chromedriver and downloaded chrome directly from their website. 我卸载了chromedriver,并直接从他们的网站下载了chrome。 The executable file should be stored in /usr/bin. 可执行文件应存储在/ 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. PS:您不再需要使用watir-webdriver,因为watir现在包含在最新版本中。 That is why it is not included in this example. 这就是为什么它不包含在此示例中的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.