SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.18k stars 8.11k forks source link

[šŸ› Bug]: Minitest::UnexpectedError: Selenium::WebDriver::Error::NoSuchWindowError: no such window #14431

Closed Pepan closed 2 weeks ago

Pepan commented 2 weeks ago

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?

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_
github-actions[bot] commented 2 weeks ago

@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 commented 2 weeks ago

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 commented 2 weeks ago

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 commented 2 weeks ago

Hello @aguspe, no.

Look at screenshots.

SniĢmek obrazovky 2024-08-26 vĀ 9 50 19 SniĢ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 commented 2 weeks ago

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

aguspe commented 2 weeks ago

Hello @aguspe, no.

Look at screenshots.

SniĢmek obrazovky 2024-08-26 vĀ 9 50 19 SniĢ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 commented 2 weeks ago

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 commented 2 weeks ago

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

aguspe commented 2 weeks ago

Thank you so much @Pepan have a great day!