mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.2k stars 1.52k forks source link

Can't locate element within a ShadowRoot #2005

Closed titusfortner closed 1 year ago

titusfortner commented 2 years ago

System

Testcase

Note: Same behavior for find_elements

https://github.com/SeleniumHQ/selenium/blob/trunk/common/src/web/webComponents.html

custom_element = driver.find_element(css: 'custom-checkbox-element')
shadow_root = custom_element.shadow_root
shadow_root.find_element(css: 'input')

Stacktrace

Selenium::WebDriver::Error::WebDriverError: unexpected response, code=405, content-type="text/plain"
HTTP method not allowed

Trace-level log

2022-04-13 11:01:53 INFO Selenium -> GET session/9c72ed62-5f04-43f5-9fe3-dd7e2e82f6ad/element/269c9476-2d0d-44d1-ae9f-8751aa0ee103/shadow
1649865713374   webdriver::server   DEBUG   -> GET /session/9c72ed62-5f04-43f5-9fe3-dd7e2e82f6ad/element/269c9476-2d0d-44d1-ae9f-8751aa0ee103/shadow 
1649865713375   Marionette  DEBUG   0 -> [0,4,"WebDriver:GetShadowRoot",{"id":"269c9476-2d0d-44d1-ae9f-8751aa0ee103"}]
1649865713377   Marionette  DEBUG   0 <- [1,4,null,{"value":{"shadow-6066-11e4-a52e-4f735466cecf":"d5922422-e71b-4196-a03e-21049e31b710"}}]
1649865713378   webdriver::server   DEBUG   <- 200 OK {"value":{"shadow-6066-11e4-a52e-4f735466cecf":"d5922422-e71b-4196-a03e-21049e31b710"}}
2022-04-13 11:01:53 INFO Selenium <- {"value":{"shadow-6066-11e4-a52e-4f735466cecf":"d5922422-e71b-4196-a03e-21049e31b710"}}
2022-04-13 11:01:53 INFO Selenium -> POST session/9c72ed62-5f04-43f5-9fe3-dd7e2e82f6ad/shadow/d5922422-e71b-4196-a03e-21049e31b710/element
2022-04-13 11:01:53 INFO Selenium    >>> http://127.0.0.1:4444/session/9c72ed62-5f04-43f5-9fe3-dd7e2e82f6ad/shadow/d5922422-e71b-4196-a03e-21049e31b710/element | {"using":"css selector","value":"input"}
2022-04-13 11:01:53 DEBUG Selenium      > {"Accept"=>"application/json", "Content-Type"=>"application/json; charset=UTF-8", "User-Agent"=>"selenium/4.1.0 (ruby macosx)", "Content-Length"=>"40"}
2022-04-13 11:01:53 INFO Selenium <- HTTP method not allowed
whimboo commented 2 years ago

This is not implemented yet. See https://bugzilla.mozilla.org/show_bug.cgi?id=1700097

antonalgeorge commented 2 years ago

Is there any update on this?

tbieniek commented 2 years ago

Any progress with this issue ? I cannot test app that uses shadow DOM using Selenium

whimboo commented 1 year ago

This is fixed in Firefox 113.

orensch2 commented 1 year ago

It works with Firefox 113.0.1 (64-bit) with geckodriver-v0.33.0-linux64 It doesn't work with almost any other combination of Firefox/geckodriver I've tried.

I've encountered an error using Selenium with python: shadow_host = driver.find_element(By.TAG_NAME, 'some tag') shadow_host.shadow_root.find_element(By.CSS_SELECTOR, 'some css_selector') ---> "selenium.common.exceptions.WebDriverException: Message: HTTP method not allowed"

This was the case for the current Firefox version while writing this post: 118.0.2 (64-bit); and also for 113.0.1 (64-bit)

I've tried several geckodriver versions, specifically geckodriver-v0.31.0-linux64 (title of this thread) in combination with both versions. Finally, as I wrote in the beginning of the post, I was able to interact with ShadowRoot object using Firefox 113 (current version is 118*) and the latest geckodriver (0.33.0-linux64).

whimboo commented 1 year ago

@orensch2 please make sure that the right version of geckodriver is used. You can check that by the returned session capabilities as well. If that's still happening with recent Firefox and geckodriver please file a new issue with trace logs attached. Thanks.