Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Minitest::UnexpectedError: Selenium::WebDriver::Error::NoSuchWindowError: no such window #14431

Closed
Pepan opened this issue Aug 23, 2024 · 9 comments

Comments

@Pepan
Copy link

Pepan commented Aug 23, 2024

What happened?

Error happened :

Minitest::UnexpectedError: Selenium::WebDriver::Error::NoSuchWindowError: no such window
  (Session info: chrome=128.0.6613.85)
    /Users/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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'
    ```


### How can we reproduce the issue?

```shell
Just running system test as usually. After new Chrome installed.

Relevant log output

Running 7 tests in a single process (parallelization threshold is 50)
Capybara starting Puma...
* Version 6.4.2, codename: The Eagle of Durango
* Min threads: 0, max threads: 4
* Listening on http://127.0.0.1:50003

Minitest::UnexpectedError: Selenium::WebDriver::Error::NoSuchWindowError: no such window
  (Session info: chrome=128.0.6613.85)
    /Users/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/ruby-3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara/session.rb:132:in `reset!'
    /Users/josefchmel/.rvm/rubies/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/josefchmel/.rvm/rubies/ruby-3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara.rb:327:in `reverse_each'
    /Users/josefchmel/.rvm/rubies/ruby-3.3.4/lib/ruby/gems/3.3.0/gems/capybara-3.40.0/lib/capybara.rb:327:in `reset_sessions!'
    /Users/josefchmel/.rvm/rubies/ruby-3.3.4/lib/ruby/gems/3.3.0/gems/actionpack-7.2.1/lib/action_dispatch/system_testing/test_helpers/setup_and_teardown.rb:16:in `after_teardown'


### Operating System

macOS Sonoma 14.6.1 (23G93)

### Selenium version

selenium-webdriver (4.23.0, 4.19.0), Ruby 3.3.3

### What are the browser(s) and version(s) where you see this issue?

Chrome 128.0.6613.85

### What are the browser driver(s) and version(s) where you see this issue?

(Session info: chrome=128.0.6613.85)

### Are you using Selenium Grid?

_No response_
Copy link

@Pepan, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@Pepan
Copy link
Author

Pepan commented Aug 23, 2024

solution : --disable-search-engine-choice-screen send this option to Chrome

    driven_by :selenium, using: :chrome, screen_size: [1400, 1400] do |driver_option|
      driver_option.add_argument '--disable-search-engine-choice-screen'
    end

@aguspe
Copy link
Contributor

aguspe commented Aug 24, 2024

Hello @Pepan just to double check this doesn't seem to be a selenium issue, since I cannot reproduce it but on your test you were not able to select the right window and you needed to disable the search engine selection option

if that's the case I will propose to close this

@Pepan
Copy link
Author

Pepan commented Aug 26, 2024

Hello @aguspe, no.

Look at screenshots.

Snímek obrazovky 2024-08-26 v 9 50 19 Snímek obrazovky 2024-08-26 v 9 50 59

After I add argument (see my above reply) it starts working again.
So it starts to happening without developers intervention and dev. can do nothing to solve it. ... it is caused probably by EU rules which Google must follow ... I guess. Maybe in your country this "choose search engine screen" does not appear.

@pujagani
Copy link
Contributor

https://www.selenium.dev/blog/2024/chrome-browser-woes/ If the proposed solution works, can we close this?

@aguspe
Copy link
Contributor

aguspe commented Aug 26, 2024

Hello @aguspe, no.

Look at screenshots.

Snímek obrazovky 2024-08-26 v 9 50 19 Snímek obrazovky 2024-08-26 v 9 50 59
After I add argument (see my above reply) it starts working again. So it starts to happening without developers intervention and dev. can do nothing to solve it. ... it is caused probably by EU rules which Google must follow ... I guess. Maybe in your country this "choose search engine screen" does not appear.

I'm also in the EU and I can see this browser selection screen but that comes from google itself not selenium, so as @pujagani if after adding the flag to disable the search eangine selection works, the issue doesn't seem to be selenium related but chrome related

I can try to reproduce it again, but I can't, for more information:

https://www.ghacks.net/2023/12/09/google-chrome-to-display-choose-your-search-engine-prompt/

And as @pujagani refer already the blog regarding passing the flag

@aguspe
Copy link
Contributor

aguspe commented Aug 26, 2024

Just as an example @Pepan, the following code throws an error:

# test_example.rb

require 'minitest/autorun'
require 'selenium-webdriver'

class ExampleTest < Minitest::Test

  def setup
    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument('--window-size=1400,1400') # Set the window size

    @driver = Selenium::WebDriver.for :chrome, options: options
  end

  def teardown
    @driver.quit
  end

  def test_visiting_example_page
    @driver.navigate.to 'https://google.com'
    search_bar = @driver.find_element(xpath: '//*[@title="Search"]')
    search_bar.send_keys 'Dogs'
    assert_equal 'Dogs', @driver.title, 'Page title should have dogs'
  end
end

Without me passing the flag '--disable-search-engine-choice-screen'because it cannot interact with the element due to the default engine selection being in front of it, so it's not a Selenium issue but an issue due to this new selector in Chrome

@Pepan
Copy link
Author

Pepan commented Aug 27, 2024

I understand ... but it halted on selenium/webdriver/remote/response.rb:62:in add_cause'` so I posted it here.

@Pepan Pepan closed this as completed Aug 27, 2024
@aguspe
Copy link
Contributor

aguspe commented Aug 27, 2024

Thank you so much @Pepan have a great day!

glaszig added a commit to glaszig/rails that referenced this issue Sep 5, 2024
starting chrome with a fresh profile shows a search engine choice screen
which will break any tests. passing a special argument will disable the
screen.

see SeleniumHQ/selenium#14431
glaszig added a commit to glaszig/rails that referenced this issue Sep 6, 2024
starting chrome with a fresh profile shows a search engine choice screen
which will break any tests. passing a special argument will disable the
screen.

see SeleniumHQ/selenium#14431

also:
- refactor default chrome option initialization
- compress browser option initialization
garrettblehm pushed a commit to garrettblehm/rails that referenced this issue Sep 9, 2024
starting chrome with a fresh profile shows a search engine choice screen
which will break any tests. passing a special argument will disable the
screen.

see SeleniumHQ/selenium#14431

also:
- refactor default chrome option initialization
- compress browser option initialization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants