我们正在使用 selenium web 驱动程序和 python 进行测试自动化,并尝试使用 shadow dom 设计自动化 html5 应用程序。无法识别 shadow-root 下的任何元素。例如。如果我想访问下面给出的影子根下的任何元素,那么我该怎么做?任何帮助表示赞赏。
我一直在关注如何使用硒自动实现阴影DOM元素的讨论。与#shadow-root (open)元素一起工作。
在通过“ 硒”访问url时出现Clear data的“ 清除浏览数据”弹出窗口中定位按钮的过程中,我无法找到以下元素:chrome://settings/clearBrowserData
#shadow-root (open)
<settings-privacy-page>
Run Code Online (Sandbox Code Playgroud)
快照:
使用Selenium,以下是我的代码试用以及遇到的相关错误:
尝试1:
WebElement root5 = shadow_root4.findElement(By.tagName("settings-privacy-page"));
Run Code Online (Sandbox Code Playgroud)
错误:
Exception in thread "main" org.openqa.selenium.JavascriptException: javascript error: b.getElementsByTagName is not a function
Run Code Online (Sandbox Code Playgroud)尝试2:
WebElement root5 = shadow_root4.findElement(By.cssSelector("settings-privacy-page"));
Run Code Online (Sandbox Code Playgroud)
错误:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"settings-privacy-page"}
Run Code Online (Sandbox Code Playgroud)尝试3:
WebElement root5 = (WebElement)((JavascriptExecutor)shadow_root4).executeScript("return document.getElementsByTagName('settings-privacy-page')[0]");
Run Code Online (Sandbox Code Playgroud)
错误:
Exception in thread "main" java.lang.ClassCastException: org.openqa.selenium.remote.RemoteWebElement cannot be cast to org.openqa.selenium.JavascriptExecutor …Run Code Online (Sandbox Code Playgroud)