gpt4 book ai didi

java - 需要帮助点击阴影Root(闭合)类型下的元素

转载 作者:行者123 更新时间:2023-12-02 01:28:25 26 4
gpt4 key购买 nike

单击位于阴影根内部的元素时出现空指针异常(已关闭)

尝试用 Java 脚本处理它:

public WebElement getShadowRootElement(WebElement element) {
return (WebElement)
((JavascriptExecutor)
driver).executeScript("return
arguments[0].shadowRoot", element);
}

enter image description here

结果:

Cannot read property 'shadowRoot' of null

添加了屏幕截图:1.enter image description here

enter image description here

最佳答案

如果您的用例是与 <path> 交互<svg> 内的元素标签,确实在 #shadow-root (closed)

@hayatoito(Shadow DOM 的创建者)在 comment明确提到:

The original motivation of introducing a closed shadow tree is "Never allow an access to a node in a closed shadow tree, via any APIs, from outside", AFAIK. Like that we can not access a node in the internal hidden shadow tree which is used in <video> element, in Blink.

In fact, I designed a closed shadow tree in such a way. If there is a way to access a node in a closed shadow tree, it should be considered as a bug of the spec.

I think it's totally okay to have an API to allow an access in the layer of Chrome apps or extensions. However, for a normal web app, I think the current agreement is "Never allow it".

If we allowed it, that means we do not need a closed shadow tree. Just having an open shadow tree is enough, I think.

<小时/>

WebDriver 视角

最近,@AutomatedTester [Mozilla Corporation 首席培根官 David Burns] 发起了关于 WebDriver - Testability of web components 的讨论

目前,Selenium 团队已开放接受拉取请求。

<小时/>

片尾

在这里您可以找到关于 How to automate shadow DOM elements using selenium? 的相关讨论

关于java - 需要帮助点击阴影Root(闭合)类型下的元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56500290/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com