Home > other >  Selenium Webdriver can't find "navigate" element in Ruby
Selenium Webdriver can't find "navigate" element in Ruby

Time:10-06

I am new to this so it may be obvious, but I am struggling with getting my test to run the "navigate" element. Or Object. Whatever it is. Here is my code:

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")

There's more to this test but it isn't relevant to my question. What am I missing? Do I need to install another gem or driver? I've searched everywhere for this answer and can't find it.

I've also tried running it with:

driver.navigate.go

and that fails as well. Says it cannot find the "navigate" element.

Thanks for your help!

CodePudding user response:

You are missing initializing of your wanted web driver. However you didn't post your current version of selenium, so I assumed it was last version.
Here is what documentation says about Selenium::WebDriver.

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

Create a new Driver instance with the correct bridge for the given browser One special argument is not passed on to the bridges, :listener. You can pass a listener for this option to get notified of WebDriver events. The passed object must respond to #call or implement the methods from AbstractEventListener.

So in your case you need to change you driver variable

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

WebDriver docs

CodePudding user response:

Here is the simple code which should help you

require 'selenium-webdriver'

driver=Selenium::WebDriver.for :firefox

driver.navigate.to("https://www.google.com/")
  • Related