Closed
Description
What happened?
As below, when I create Selenium::WebDriver instance with Chrome Beta (v120) and the headless mode option and call the logs method, I get a NoMethodError.
require 'selenium-webdriver'
options = Selenium::WebDriver::Options.chrome(browser_version: 'beta')
options.args << '--headless'
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.logs
#=> undefined method `logs' for #<Selenium::WebDriver::Chrome::Driver:0x487c57d05253aecc browser=:"chrome-headless-shell"> (NoMethodError)
In contrast, with the stable version (v119) of Chrome there is no problem.
require 'selenium-webdriver'
options = Selenium::WebDriver::Options.chrome(browser_version: 'stable')
options.args << '--headless'
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.logs
# => works fine
After investigating, I found that driver.bridge.browser
is :"chrome-headless-shell"
in Chrome Beta + headless mode, and the following code is not properly handled.
selenium/rb/lib/selenium/webdriver/common/driver.rb
Lines 330 to 344 in 0c86525
Investigation code
require 'selenium-webdriver'
browser_versions = %w(stable beta)
browser_versions.each do |browser_version|
options = Selenium::WebDriver::Options.chrome(browser_version: browser_version)
options.args << '--headless'
driver = Selenium::WebDriver.for(:chrome, options: options)
puts "browser_version: #{browser_version}"
puts "driver.respond_to?(:logs): #{driver.respond_to?(:logs)}"
puts "driver.bridge.browser: #{driver.send(:bridge).browser}"
puts
end
Output
browser_version: stable
driver.respond_to?(:logs): true
driver.bridge.browser: chrome
browser_version: beta
driver.respond_to?(:logs): false
driver.bridge.browser: chrome-headless-shell
How can we reproduce the issue?
require 'selenium-webdriver'
options = Selenium::WebDriver::Options.chrome(browser_version: 'beta')
options.args << '--headless'
driver = Selenium::WebDriver.for(:chrome, options: options)
driver.logs
### Relevant log output
```shell
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] Selenium Manager binary found at /Users/hoshino_ta/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/selenium-webdriver-4.15.0/bin/macos/selenium-manager
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] Executing Process ["/Users/hoshino_ta/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/selenium-webdriver-4.15.0/bin/macos/selenium-manager", "--browser", "chrome", "--browser-version", "beta", "--output", "json", "--debug"]
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] chromedriver not found in PATH
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] chrome not found in PATH
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] chrome beta not found in the system
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] Required browser: chrome 120.0.6099.5
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] chrome 120.0.6099.5 already exists
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] chrome 120.0.6099.5 is available at /Users/hoshino_ta/.cache/selenium/chrome/mac-x64/120.0.6099.5/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] Required driver: chromedriver 120.0.6099.5
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] chromedriver 120.0.6099.5 already in the cache
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] Driver path: /Users/hoshino_ta/.cache/selenium/chromedriver/mac-x64/120.0.6099.5/chromedriver
2023-11-08 13:16:42 DEBUG Selenium [:selenium_manager] Browser path: /Users/hoshino_ta/.cache/selenium/chrome/mac-x64/120.0.6099.5/Google Chrome for Testing.app/Contents/MacOS/Google Chrome for Testing
Starting ChromeDriver 120.0.6099.5 (dc7563588833ccad6482a3aa5848108c4387e7e5-refs/branch-heads/6099@{#21}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
selenium.rb:10:in `<main>': undefined method `logs' for #<Selenium::WebDriver::Chrome::Driver:0x29e4ce086854de18 browser=:"chrome-headless-shell"> (NoMethodError)
driver.logs
^^^^^
Operating System
macOS Monterey
Selenium version
Ruby 4.15.0 (Ruby: 3.1.0, selenium-webdriver: 4.15.0)
What are the browser(s) and version(s) where you see this issue?
Chrome Beta (120.0.6099.5)
What are the browser driver(s) and version(s) where you see this issue?
chromedriver 120.0.6099.5
Are you using Selenium Grid?
No response