今天,当我使用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秒内运行。
lsof -i TCP:7054
使用-d(或setting $DEBUG = true)运行ruby 还将提供一些有用的信息,以进一步调试它。
$DEBUG = true