Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:11:35+00:00 2026-05-31T16:11:35+00:00

From my understanding of the docs this general approach should work: begin try1 rescue

  • 0

From my understanding of the docs this general approach should work:

begin
 try1
rescue
 try2
rescue
 try3
.
.
.
rescue
 puts "Everybody failed, sorry man!"
end

However whenever I try to open up a Watir-Webdriver browser, it never seems to try beyond the second $browser = Watir::Browser.new, ending the script in line 189 with Connection refused – connect(2) (Errno::ECONNREFUSED)

Code.rb:

begin
 $browser = Watir::Browser.new(:firefox, :profile => "botmode") # **line 186**

rescue
 $browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => :firefox)   # **line 189**

rescue  # local selenium htmlunit
  puts __LINE__.to_s + ": #{$!}"    
#  $browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => :htmlunit)  # but needs Javascript for AJAX support...
  $browser = Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true, :cssSelectorsEnabled=>true, :nativeEvents=>false) ) 

rescue # Try to use VentanaPC if still failing..  
 $browser = Watir::Browser.new(:remote, :url => "http://5.19.111.226:4444/wd/hub", :desired_capabilities => :firefox)  

rescue  # no browser left to failover to
  puts __LINE__.to_s + ": #{$@.to_s}"
end

# ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [i686-linux]

To make line 186 fail, I deliberately set DISPLAY=:88 in advance to a non-existent Xserver, so this error is okay: 186: unable to obtain stable firefox connection in 60 seconds (127.0.0.1:7055)

Where am I going wrong here, or is there a better way to do this? Is this something particular to Selenium or Watir?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:11:36+00:00Added an answer on May 31, 2026 at 4:11 pm

    Your assumption is wrong, this does not work as you expect:

    irb(main):062:0> begin
    irb(main):063:1*   raise StandardError
    irb(main):064:1> rescue
    irb(main):065:1>   puts "test1"
    irb(main):066:1>   raise StandardError
    irb(main):067:1> rescue
    irb(main):068:1>   puts "test2"
    irb(main):069:1> end
    test1
    StandardError: StandardError
        from (irb):66:in `rescue in irb_binding'
        from (irb):62
        from /usr/bin/irb:12:in `<main>'
    

    test2 is not printed. Multiple rescues are for different exception types, you can’t catch errors in other rescue blocks like that. You could instead use nested begin/rescue blocks, but this case seems complex enough to use a more general approach:

    methods = [
      lambda { Watir::Browser.new(:firefox, :profile => "botmode") },
      lambda { Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => :firefox) },
      lambda { Watir::Browser.new(:remote, :url => "http://127.0.0.1:4444/wd/hub", :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true, :cssSelectorsEnabled=>true, :nativeEvents=>false) ) },
      lambda { Watir::Browser.new(:remote, :url => "http://5.19.111.226:4444/wd/hub", :desired_capabilities => :firefox) },
    ]
    
    def get_first_successful(methods)
      methods.each do |m|
        begin
          return m.call
        rescue
        end
      end
      nil
    end
    
    $browser = get_first_successful(methods)
    

    This will select the first method which doesn’t fail. However, I don’t see how the last one could be successful if the second one failed, you might rethink your options here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

MariaDB 5.3 introduced dynamic columns. From my understanding the next version of mysql should
From what I've read in the docs, gen_servers don't trap exits. Moreover, my understanding
I know this question should be really simple, but for some reason thoroughly understanding
From my understanding, helpers are mainly used to clean up views from some view-specific
From my understanding the XMPP protocol is based on an always-on connection where you
From my understanding of the CSS spec, a table above or below a paragraph
From my understanding, Lua is an embeddable scripting language that can execute methods on
From my understanding, each of these methods: get() and put() are atomic. But, when
From my understanding by reading several articles I assumed Process Address Space(PAS) and Virtual
From what little understanding of Cassandra I have, it seems that data locality is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.