rubygoogle-chromeselenium-webdriverrspeccapybara

How to skip "Choose search engine" with capybara/selenium/chrome


When I open Chrome from capybara I get this screen:

choose search engine

here is the image on imgur because stack overflow images don't work for me: https://i.imgur.com/UE9teHL.png

That results in errors in my specs, how to skip it? e.g. choose Google for instance

Here is the stacktrace:

  1) GenerateAndEvaluateProgram works
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: fill_in "prompt", with: "1 + 1"
          
          Capybara::ElementNotFound:
            Unable to find field "prompt" that is not disabled
          # ./spec/features/generate_and_evaluate_program_spec.rb:9:in `block (2 levels) in <top (required)>'

     1.2) Failure/Error: raise ex, cause: cause
          
          Selenium::WebDriver::Error::NoSuchWindowError:
            no such window
              (Session info: chrome=127.0.6533.89)
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:62:in `add_cause'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:41:in `error'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:52:in `assert_ok'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/common.rb:101:in `new'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/common.rb:101:in `create_response'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/default.rb:103:in `request'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/http/common.rb:67:in `call'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/bridge.rb:675:in `execute'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/remote/bridge.rb:193:in `switch_to_window'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/selenium-webdriver-4.23.0/lib/selenium/webdriver/common/target_locator.rb:107:in `window'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/selenium/driver.rb:261:in `switch_to_window'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/selenium/driver.rb:402:in `within_given_window'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/selenium/driver.rb:238:in `close_window'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/selenium/driver_specializations/chrome_driver.rb:41:in `block in reset!'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/selenium/driver_specializations/chrome_driver.rb:41:in `each'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/selenium/driver_specializations/chrome_driver.rb:41:in `reset!'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/session.rb:132:in `reset!'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara.rb:327:in `block in reset_sessions!'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara.rb:327:in `reverse_each'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara.rb:327:in `reset_sessions!'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/rspec.rb:42:in `call'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/rspec.rb:42:in `each'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/rspec.rb:42:in `after_outside'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/rspec.rb:27:in `block in run'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/interception-0.5/lib/interception.rb:71:in `listen'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/core_ext.rb:74:in `enable_rescuing!'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/core_ext.rb:94:in `with_rescuing'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/core_ext.rb:15:in `block (2 levels) in rescue'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/core_ext.rb:13:in `catch'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/core_ext.rb:13:in `block in rescue'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/core_ext.rb:12:in `rescue'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/rspec.rb:14:in `run'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/pry-rescue-1.6.0/lib/pry-rescue/rspec.rb:74:in `block (2 levels) in <top (required)>'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:390:in `execute_with'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:352:in `call'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/webmock-3.23.1/lib/webmock/rspec.rb:39:in `block (2 levels) in <top (required)>'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:457:in `instance_exec'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:390:in `execute_with'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:352:in `call'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/hooks.rb:486:in `run'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example.rb:259:in `run'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:646:in `block in run_examples'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:642:in `map'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:642:in `run_examples'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/example_group.rb:607:in `run'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:121:in `map'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/configuration.rb:2091:in `with_suite_hooks'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:116:in `block in run_specs'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/reporter.rb:74:in `report'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:115:in `run_specs'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:89:in `run'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:71:in `run'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/lib/rspec/core/runner.rb:45:in `invoke'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/lib/ruby/gems/3.3.0/gems/rspec-core-3.13.0/exe/rspec:4:in `<top (required)>'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/bin/rspec:25:in `load'
          # /Users/dorianmariefr/.asdf/installs/ruby/3.3.4/bin/rspec:25:in `<main>'
          # 
          #   Showing full backtrace because every line was filtered out.
          #   See docs for RSpec::Configuration#backtrace_exclusion_patterns and
          #   RSpec::Configuration#backtrace_inclusion_patterns for more information.
          # ------------------
          # --- Caused by: ---
          # Selenium::WebDriver::Error::WebDriverError:
          #   0   chromedriver                        0x0000000104ef9088 cxxbridge1$str$ptr + 1887276
1   chromedriver                        0x0000000104ef1764 cxxbridge1$str$ptr + 1856264
2   chromedriver                        0x0000000104b00694 cxxbridge1$string$len + 88116
3   chromedriver                        0x0000000104b70100 cxxbridge1$string$len + 545440
4   chromedriver                        0x0000000104b39474 cxxbridge1$string$len + 321044
5   chromedriver                        0x0000000104b3a0e4 cxxbridge1$string$len + 324228
6   chromedriver                        0x0000000104ec0a6c cxxbridge1$str$ptr + 1656336
7   chromedriver                        0x0000000104ec54c8 cxxbridge1$str$ptr + 1675372
8   chromedriver                        0x0000000104ea6950 cxxbridge1$str$ptr + 1549556
9   chromedriver                        0x0000000104ec5c78 cxxbridge1$str$ptr + 1677340
10  chromedriver                        0x0000000104e98660 cxxbridge1$str$ptr + 1491460
11  chromedriver                        0x0000000104ee2ac0 cxxbridge1$str$ptr + 1795684
12  chromedriver                        0x0000000104ee2c3c cxxbridge1$str$ptr + 1796064
13  chromedriver                        0x0000000104ef1398 cxxbridge1$str$ptr + 1855292
14  libsystem_pthread.dylib             0x0000000192e2af94 _pthread_start + 136
15  libsystem_pthread.dylib             0x0000000192e25d34 thread_start + 8

Solution

  • You can skip Chrome's “Choose your search engine” dialog by setting the disable-search-engine-choice-screen argument.

    This is how my Capybara/Selenium config looks like:

    require 'capybara/rails'
    require 'capybara/rspec'
    
    Capybara.server = :puma, { Silent: true }
    Capybara.server_port = 3000
    
    Capybara.register_driver :chrome do |app|
      chrome_options = Selenium::WebDriver::Chrome::Options.new
      chrome_options.add_argument('--disable-search-engine-choice-screen')
      chrome_options.add_argument('--window-size=1920,1080')
    
      chrome_options.add_argument('--headless') if ENV['CAPYBARA_HEADLESS'].present?
    
      Capybara::Selenium::Driver.new(app, browser: :chrome, options: chrome_options)
    end
    
    Capybara.default_driver    = :chrome
    Capybara.javascript_driver = :chrome