【问题标题】:Selenium Webdriver can't find "navigate" element in RubySelenium Webdriver 在 Ruby 中找不到“导航”元素
【发布时间】:2021-11-26 11:53:51
【问题描述】:

我是新手,所以这可能很明显,但我正在努力让我的测试运行“导航”元素。或对象。不管是什么。这是我的代码:

require "selenium-webdriver"
require "rspec"

# TEST: Sign up for blog
describe "Blog application" do
  describe "signup to the blog application" do
    it "confirm that a user can successfully signup" do
        driver = Selenium::WebDriver::Firefox
        # Go to signup form
        driver.get "https://selenium-blog.herokuapp.com/signup"
        # Fill out and submit form
        username_field = driver.find_element(id: 'user_username')
        username_field.send_keys("user")

此测试还有更多内容,但与我的问题无关。我错过了什么?我需要安装另一个 gem 或驱动程序吗?我到处搜索这个答案,但找不到。

我也尝试过运行它:

driver.navigate.go

这也失败了。说它找不到“导航”元素。

感谢您的帮助!

【问题讨论】:

    标签: ruby selenium selenium-webdriver


    【解决方案1】:

    您缺少所需的网络驱动程序的初始化。但是你没有发布你当前版本的 selenium,所以我认为它是最后一个版本。
    以下是文档中关于 Selenium::WebDriver 的内容。

    .for(browser) ⇒ Driver
    .for(browser, opts) ⇒ Driver
    

    使用给定浏览器的正确网桥创建一个新的 Driver 实例 一个特殊的参数没有传递给桥,:listener。您可以为此选项传递一个侦听器以获取有关 WebDriver 事件的通知。传递的对象必须响应 #call 或实现 AbstractEventListener 中的方法。

    所以在你的情况下你需要改变你的驱动变量

    driver = Selenium::WebDriver.for(:firefox)
    # ...
    

    WebDriver docs

    【讨论】:

    • 好的,我更新了我的脚本,现在它给了我这个错误:Failure/Error: driver = Selenium::WebDriver.for(:firefox) ArgumentError: wrong number of arguments (given 1, expected 0)
    • 下面是脚本现在的样子:<br>require "selenium-webdriver"<br/> require "rspec"<br/> <br/> # TEST: Sign up for blog describe "Blog application" do describe "signup to the blog application" do it "confirm that a user can successfully signup" do driver = Selenium::WebDriver.for(:firefox) # Go to signup form driver.navigate.to "https://selenium-blog.herokuapp.com/signup" # Fill out and submit form username_field = driver.find_element(id: 'user_username') username_field.send_keys("user")
    • 请发布您的硒版本。它可以在 Gemfile(如果指定)或 Gemfile.lock 中找到
    【解决方案2】:

    下面是对你有帮助的简单代码

    require 'selenium-webdriver'
    
    driver=Selenium::WebDriver.for :firefox
    
    driver.navigate.to("https://www.google.com/")
    

    【讨论】:

      猜你喜欢
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 2016-09-07
      • 2017-10-24
      • 1970-01-01
      • 1970-01-01
      • 2017-07-17
      相关资源
      最近更新 更多