watir

Hover method is not working when shadow root is used


I located the element using shadowroot like shown below

loc = locator.split("=")
element=@browser.element(loc.first => loc.last)
        .shadow_root
        .text_field

I am currently able to click on the element without any issues, however, upon attempting to hover over it, the following error occurs

"undefined method `driver' for #<Watir::ShadowRoot:0x0806d828 @query_scope=#<Watir::HTMLElement: located: true; {\"id\"=>\"user.name\"}>, @shadow_root=#<Selenium::WebDriver::ShadowRoot:0x..fd1bb37b8 id=\"8870eb8d-d11c-4a03-9ae9-1d6780e109a2\">>\n\n      @query_scope.driver\n                  ^^^^^^^"

Solution

  • From a quick test, looks like we just need to define the method and everything will work.

    Can you try monkey-patching your Watir?

    module Watir
      class ShadowRoot
        def driver
          browser.driver
        end
      end
    end
    

    If that works, we can get it incorporated into the actual code base.