今天,当我使用selenium webdrive,我有一个错误.我的平台是mac osx.这是我的例外日志.
ruby-1.9.2-p0 > Selenium::WebDriver.for :firefox Selenium::WebDriver::Error::WebDriverError: unable to bind to locking port 7054 within 45 seconds from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/socket_lock.rb:48:in `lock' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/socket_lock.rb:29:in `locked' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/launcher.rb:32:in `launch' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/firefox/bridge.rb:21:in `initialize' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/common/driver.rb:38:in `new' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver/common/driver.rb:38:in `for' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/selenium-webdriver-0.1.0/lib/selenium/webdriver.rb:51:in `for' from (irb):8 from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:44:in `start' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands/console.rb:8:in `start' from /Users/Apple/.rvm/gems/ruby-1.9.2-p0/gems/railties-3.0.1/lib/rails/commands.rb:23:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>'
我不知道为什么会发生.我的firefox路径是默认路径.
感谢您的帮助!!
解决方法
WebDriver使用端口7054(“锁定端口”)作为互斥体,以确保我们不会同时启动两个Firefox实例.您创建的每个新实例将在启动浏览器之前等待互斥体,然后在浏览器打开时立即释放它.
所以这可能是一个资源问题 – 以前创建的驱动程序需要超过45秒的时间才能启动,并且持续到这个时间的锁定.
如果这种情况似乎不太可能,那么知道握住锁的过程是很有趣的.尝试运行lsof -i TCP:7054在45秒之前超时.
用-d(或设置$DEBUG = true)运行ruby还将提供一些有用的信息来进一步调试.