selenium/webdriver/firefox/binary.rb:134:in `path': can't modify frozen String (FrozenError)

北慕城南 提交于 2019-12-11 10:09:30

问题


I tried to run a simple google look up code in selenium and ran it on EC2 instance(Amazon Linux). I am getting an error launching Firefox and cannot understand what the error means.

Ruby version - ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-linux] selenium-webdriver version - 3.142.3

require 'selenium-webdriver'

options = Selenium::WebDriver::Firefox::Options.new(args: ['-headless'])
driver = Selenium::WebDriver.for(:firefox, options: options)

driver.get "http://google.com"

puts "Page title is #{driver.title}"

driver.quit

When running ruby test.rb

Traceback (most recent call last):
    8: from test.rb:4:in `<main>'
    7: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver.rb:88:in `for'
    6: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:54:in `for'
    5: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/driver.rb:33:in `new'
    4: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/driver.rb:33:in `new'
    3: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/marionette/driver.rb:38:in `initialize'
    2: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/driver.rb:299:in `service_url'
    1: from /usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/common/service.rb:45:in `firefox'
/usr/local/rvm/gems/ruby-2.6.3/gems/selenium-webdriver-3.142.3/lib/selenium/webdriver/firefox/binary.rb:134:in `path': can't modify frozen String (FrozenError)

Need some help here.


回答1:


You'll get that error if Firefox isn't installed, or isn't accessible on your path.

Reinstall if you already have it.




回答2:


Also, as of selenium-webdriver 3.142.3, you can check the current Firefox binary path using this:

Selenium::WebDriver::Firefox::Binary.path

This would throw this same FrozenError if no binary is found, and return the binary path if a Firefox binary has been found somewhere.

Also worth mentioning that an issue has been opened in the selenium-webdriver repo to make the error message more explanatory, if you're interested.



来源:https://stackoverflow.com/questions/56523308/selenium-webdriver-firefox-binary-rb134in-path-cant-modify-frozen-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!