Skip to content

[🐛 Bug]: ruby - Selenium::WebDriver::Error::InvalidArgumentError: invalid argument: 'handle' must be a string #14653

@chughes

Description

@chughes

What happened?

We are experiencing intermittent and seemingly random test failures locally and in CI where chromedriver responds with "invalid argument: 'handle' must be a string" to a call from Selenium to get window handles. Detailed logs are included below.

How can we reproduce the issue?

ruby: 3.1.4p223
capybara: 3.40.0
selenium-webdriver: 4.25.0
chromedriver: 130.0.6723.69

tests failures can happen in any of our feature tests somewhat randomly where one run fails but will pass when re-run. The failures are reported around lines like:

expect(page).to have_content("xyz", wait: 20)

The error is reported as:
     1.1) Failure/Error: expect(page).to have_content("xyz", wait: 20)
          
          NoMethodError:
            undefined method `map' for 1:Integer
          
                      ids.map { |id| Bridge.element_class.new self, element_id_from(id) }
                         ^^^^
            Did you mean?  tap

     1.2) Failure/Error: raise ex, cause: cause
          
          Selenium::WebDriver::Error::InvalidArgumentError:
            invalid argument: 'handle' must be a string
              (Session info: chrome=130.0.6723.70)

I have included debug logs below and can try to recreate in a separate repo independent of our codebase if necessary.

Relevant log output

2024-10-25 15:21:52 DEBUG Selenium [:command] -> POST session/a7def88c1a04f1c586768fd0f05226d0/window 
2024-10-25 15:21:52 DEBUG Selenium [:command]    >>> http://127.0.0.1:9515/session/a7def88c1a04f1c586768fd0f05226d0/window | {"handle":{"element-6066-11e4-a52e-4f735466cecf":"f.7AB7119F5249502AE0F8482306FC499C.d.6A5B956DD7D43976E148E3D249883075.e.34"}} 
2024-10-25 15:21:52 DEBUG Selenium [:header]      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/4.25.0 (ruby macosx)", "Content-Length"=>"127"} 
[1729894912.583][INFO]: [a7def88c1a04f1c586768fd0f05226d0] COMMAND SwitchToWindow {
   "handle": {
      "element-6066-11e4-a52e-4f735466cecf": "f.7AB7119F5249502AE0F8482306FC499C.d.6A5B956DD7D43976E148E3D249883075.e.34"
   }
}
2024-10-25 15:21:52 DEBUG Selenium [:header]    <<<  {"content-length"=>["46"], "content-type"=>["application/json; charset=utf-8"], "cache-control"=>["no-cache"]} 
2024-10-25 15:21:52 DEBUG Selenium [:command] <- {"value":["7AB7119F5249502AE0F8482306FC499C"]} 
[1729894912.583][INFO]: [a7def88c1a04f1c586768fd0f05226d0] RESPONSE SwitchToWindow ERROR invalid argument: 'handle' must be a string
  (Session info: chrome=130.0.6723.70)
2024-10-25 15:21:52 DEBUG Selenium [:command] -> GET session/a7def88c1a04f1c586768fd0f05226d0/window/handles 
[1729894912.583][INFO]: [a7def88c1a04f1c586768fd0f05226d0] COMMAND GetWindows {
}
[1729894912.583][DEBUG]: DevTools WebSocket Command: Target.getTargets (id=36283) (session_id=) browser {
}
2024-10-25 15:21:52 DEBUG Selenium [:header]    <<<  {"content-length"=>["1561"], "content-type"=>["application/json; charset=utf-8"], "cache-control"=>["no-cache"]} 
2024-10-25 15:21:52 DEBUG Selenium [:command] <- {"value":{"error":"invalid argument","message":"invalid argument: 'handle' must be a string\n  (Session info: chrome=130.0.6723.70)","stacktrace":"0   chromedriver                        0x000000010345f634 cxxbridge1$str$ptr + 3645404\n1   chromedriver                        0x0000000103457e94 cxxbridge1$str$ptr + 3614780\n2   chromedriver                        0x0000000102ec4104 cxxbridge1$string$len + 88416\n3   chromedriver                        0x0000000102f33114 cxxbridge1$string$len + 543088\n4   chromedriver                        0x0000000102efaf54 cxxbridge1$string$len + 313264\n5   chromedriver                        0x0000000102efbba4 cxxbridge1$string$len + 316416\n6   chromedriver                        0x000000010342a1d4 cxxbridge1$str$ptr + 3427196\n7   chromedriver                        0x000000010342d518 cxxbridge1$str$ptr + 3440320\n8   chromedriver                        0x00000001034115f8 cxxbridge1$str$ptr + 3325856\n9   chromedriver                        0x000000010342dddc cxxbridge1$str$ptr + 3442564\n10  chromedriver                        0x000000010340287c cxxbridge1$str$ptr + 3265060\n11  chromedriver                        0x0000000103448884 cxxbridge1$str$ptr + 3551788\n12  chromedriver                        0x0000000103448a00 cxxbridge1$str$ptr + 3552168\n13  chromedriver                        0x0000000103457b2c cxxbridge1$str$ptr + 3613908\n14  libsystem_pthread.dylib             0x0000000188a21f94 _pthread_start + 136\n15  libsystem_pthread.dylib             0x0000000188a1cd34 thread_start + 8\n"}} 
[1729894912.583][DEBUG]: DevTools WebSocket Response: Target.getTargets (id=36283) (session_id=) browser {
   "targetInfos": [ {
      "attached": true,
      "browserContextId": "9FEEAF8971EE19927D1B59D8DC629E42",
      "canAccessOpener": false,
      "targetId": "7AB7119F5249502AE0F8482306FC499C",
      "title": "Motion iQ",
      "type": "page",
      "url": "http://127.0.0.1:65110/pathways/1"
   } ]
}
[1729894912.583][INFO]: [a7def88c1a04f1c586768fd0f05226d0] RESPONSE GetWindows [ "7AB7119F5249502AE0F8482306FC499C" ]

Operating System

macOS Sonoma 14.6.1

Selenium version

ruby: 3.1.4p223, selenium-webdriver: 4.25.0

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

chrome 130.0.6723.70

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

chromedriver 130.0.6723.69

Are you using Selenium Grid?

na

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-defectSomething is not working as intendedI-questionApplied to questions. Issues should be closed and send the user to community resources.J-issue-templateApplied to issues not following the template, or missing information.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions