在官方W3c webdirver文档中,明确指出位置策略是:
State Keyword
CSS selector "css selector"
Link text selector "link text"
Partial link text selector "partial link text"
Tag name "tag name"
XPath selector "xpath"
Run Code Online (Sandbox Code Playgroud)
但是,Selenium的电线协议允许:
class name
css selector
id
name
link text
partial link text
tag name
xpath
Run Code Online (Sandbox Code Playgroud)
在理论中,Selenium的文档已经过时,"真实"的故事在新的规范文档中.然而...
我在最新的Chrome自己的Webdriver上运行了一些测试,我可以确认这一点,name
并且class name
两者都有效; 但是,它们不符合规格.
我记得在Chromium问题上阅读他们只会实现官方的Webdriver规范.
现在:我知道通用答案,其中"规格并不总是100%遵循"等.但是,我想知道的是:
javascript selenium google-chrome chromium chrome-web-driver
我正在使用 Java Selenium 项目进行网页自动化。该网页包含许多我无法使用 seleniumfindElement
方法与之交互的多级 shadow-root DOM 元素。
如果您知道我可以在 Selenium Java 框架中实现的除上面列出的任何其他解决方案,请传递该解决方案。提前致谢 !。
我在将Selenium与影子DOM内的元素一起使用时遇到问题。有这个窍门吗?难道我做错了什么?
这是我的各种尝试:
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().forBrowser('chrome').build();
driver.get('https://shop.polymer-project.org/');
// Goal is to find shop-app #shadow-root app-header
//
// This is OK; no shadow DOMs
driver.findElement(webdriver.By.css('shop-app'));
// This fails because:
// NoSuchElementError: no such element: Unable to locate element
driver.findElement(webdriver.By.css('shop-app /deep/ app-header'));
// This fails because:
// NoSuchElementError: no such element: Unable to locate element
driver.findElement(webdriver.By.css('shop-app::shadow app-header'));
// This fails because:
// TypeError: Custom locator did not return a WebElement
driver.findElement(webdriver.By.js(function() {
return document.querySelector('shop-app /deep/ app-header');
})); …
Run Code Online (Sandbox Code Playgroud) 我一直在关注如何使用硒自动实现阴影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)