New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐛 Bug]: Confusing JAVA API documentation, failed to cast org.openqa.selenium.remote.ShadowRoot #10050
Comments
@RedDevil91, thank you for creating this issue. We will troubleshoot it as soon as we can. Info for maintainersTriage this issue by using labels.
If information is missing, add a helpful comment and then
If the issue is a question, add the
If the issue is valid but there is no time to troubleshoot it, consider adding the
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, W3C),
add the applicable
After troubleshooting the issue, please add the Thank you! |
After reading the issue again it can be a bit confusing. The main problem is I can't find the |
same bug like here: |
Now that Chrome supports shadow root via the driver, The only difference is that you'll need to cast to |
@titusfortner |
also the actual state is: no working solution with selenium 3.141.59? |
The actual state is that the return value of that JavaScript changed in v96 of ChromeDriver in order to be w3c compliant. Selenium 3.141.59 can not parse this new return value. You can use And I stand corrected, you need to cast to |
i dont understand: do you have a example? |
@titusfortner |
example: driver.get(webComponentUrl);
WebElement element = driver.findElement(By.css('#container'));
SearchContext context = element.getShadowRoot();
WebElement inside = context.findElement(By.cssSelector("#inside")); 4.1 should be very soon (Maybe tomorrow, more likely early next week, but no guarantees; we're all volunteers trying to coordinate updating things for 5 different languages at the same time while juggling other commitments). |
I know that Thanks! We will check 4.1 as soon as it is released. |
omg, i'm so stupid, WebElement shadowHost = seleniumWebDriver.findElement(By.cssSelector("#shadowrootcontainer")); thats it ;D |
WebElement is an interface and it does define getShadowRoot(). Your element is an instance of RemoteWebElement even if you are referencing it by the interface. |
Tried the aforementioned workaround to cast to SearchContext: java.lang.ClassCastException: com.google.common.collect.Maps$TransformedEntriesMap cannot be cast to org.openqa.selenium.SearchContext Selenium 3.14.0 |
You still need Selenium 4. |
|
my workaround is for selenium 4.0.0 because RedDevil91 comment
EDIT this point:
the telling posts here is: hope my infos are correct ;D thx titusfortner |
@datnguyen18 found a solution for you, I think. Let me know if this works: WebElement shadow_host = driver.findElement(By.id("shadow_host"));
Object shadowRoot = ((JavascriptExecutor) driver).executeScript("return arguments[0].shadowRoot", shadow_host);
String id = (String) ((Map<String, Object>) shadowRoot).get("shadow-6066-11e4-a52e-4f735466cecf");
RemoteWebElement remoteWebElement = new RemoteWebElement();
remoteWebElement.setParent(driver);
remoteWebElement.setId(id);
WebElement insideDOM = remoteWebElement.findElement(By.id("inside_dom")) |
@titusfortner Thank you very much for your solution. This works with Selenium 3.14.x. Based on our needs at the moment to temporarily support both ChromeDriver 95 and 96 with Selenium 3, here's the workaround based on your solution:
|
Thank you so much! I really wish Chrome updates would not stop breaking Selenium since they make it very difficult to get old versions or to prevent browser updates. |
More details on all these things: https://twitter.com/titusfortner/status/1462827351742500878 These updates are good for Selenium! Cross browser functionality is important. The code examples in this Issue? Do not work for Firefox. Having something specified by w3c ensures that all the drivers will implement it the same way so you know what to expect in each browser. The upgrading process is a pain, but it puts us all in a better place. |
@titusfortner Thank you getShadowRoot() works great. |
Hi need help, Using Chrome 96 with Serenitybdd 3.1.10( this uses selenium 4.0) , I am unable to access shadow DOM( switch to iframe and access object in iframe ). Please help. DOM: |
I need help with selenium-webdriver 4.1.0 to get the shadowRoot (I use Typescript as the main language in my project; I use @types/selenium-webdriver 4.0.16). public async getExtShadowRoot(selectorShadowHost: string): Promise<unknown> {
let shadowHost: WebElementPromise;
await (shadowHost = this.driver.findElement(By.css(selectorShadowHost)));
return this.driver.executeScript("return arguments[0].shadowRoot", shadowHost);
} From the above method call I get the following Promise: Promise {
ShadowRoot {
driver_: thenableWebDriverProxy {
session_: [Promise],
executor_: [Executor],
fileDetector_: null,
onQuit_: [Function: onQuit],
then: [Function: bound then],
catch: [Function: bound catch]
},
id_: '58170f1b-0247-40b4-8916-81d45f8642ed'
}
} @types/selenium-webdriver 4.0.16 does not export the ShadowRoot type. |
@mony please upgrade to 4.1 to get that API
…On Dec 11, 2021, 1:15 PM +0000, Antonio J. Domene ***@***.***>, wrote:
I need help with selenium-webdriver 4.1.0 to get the shadowRoot (I use Typescript as the main language in the project; @types/selenium-webdriver 4.0.16).
public async getExtShadowRoot(selectorShadowHost: string) { let shadowHost: WebElementPromise; await (shadowHost = this.driver.findElement(By.css(selectorShadowHost))); return this.driver.executeScript("return arguments[0].shadowRoot", shadowHost); }
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
|
I am going to assume that the message was referring to me. I am using typescript instead of java. Maybe this wasn't the best place to post this question, but it was the only place where I found the same problem I'm getting. I don't know if the typescript/JavaScript implementation is not quite finished yet. I'm just trying to get a WebElement object which is the shadowRoot and from that call findElement to get the element to click on, or whatever, iteration I need. Thanks :) I have upgraded to selenium-webdriver 4.1.0 |
You get |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
What happened?
With Chrome 96 update, our tests broke because of shadow DOM handling. I have tried to update selenium from v3.141.59 to v4.0.0 and this also breaks the code. I can solve it and it's fine but I don't understand. In the documentation I can't find the definition of this class. I have found the new
getShadowRoot()
method in the documentation. The problem is that from the code this method is only available fromRemoteWebElement
. SimpleWebElement
doesn't implement this method in the code, but the documentation still contains it. Furthermore, in the documentation thegetShadowRoot
method returnsSearchContext
and notShadowRoot
....Which documentation should I use?
Previously the attached code worked fine.
How can we reproduce the issue?
Relevant log output
Operating System
Windows 10
Selenium version
Java 4.0.0
What are the browser(s) and version(s) where you see this issue?
Chrome v96.0.4664.45
What are the browser driver(s) and version(s) where you see this issue?
chromedriver v96.0.4664.45
Are you using Selenium Grid?
No response
The text was updated successfully, but these errors were encountered: