Selenium WebDriver(java)可以与浏览器的检查工具元素选择器进行交互吗? [英] Can Selenium WebDriver (java) interact with the Browser's inspect tool element selector?
问题描述
通过使用硒,我可以访问位于检查选项卡中的浏览器元素选择器(在浏览器中为Ctrl + Shift + C)吗?
By using selenium, can I access the browsers element picker (Ctrl + Shift + C, in the browser) that is located in the inspect tab?
我想使用该选择器指向"一个元素,并使其在浏览器中高亮显示.
I want to "point" to an element using that picker and have it be high lighted in the browser.
例如,简单的东西:
WebElement elem = driver.findElement(By.id("userName"));
elem.pointer();
WebElement elem = driver.findElement(By.id("userName"));
elem.pointer();
,这将在浏览器中将元素显示为突出显示/选中的位置,这与检查"选项卡的工作原理相同.
and that would show the element as highlighted/selected in the browser, same was the inspect tab works.
推荐答案
部分是.使用 selenium-webdriver 的问题,您将能够与 google-chrome-devtools 即将使用 Java 客户端的API.
Partially Yes. Using API using the Java client soon.
="WIP中仍集成了 Chrome DevTools协议进度) 和@AdiOhana最近为网络和
Integration of the Chrome DevTools Protocol is still in WIP (Work In Progress) and @AdiOhana have recently contributed for the Network and Performance domains for a better user facing API.
在讨论中使用Selenium Webdriver控制Chrome Devtools @AdiOhana提到示例用法如下:
In the discussion Controlling Chrome Devtools with Selenium Webdriver @AdiOhana mentions of the example usage as follows:
driver.getDevTools().createSession();
driver.getDevTools().send(new Command("Profiler.enable", ImmutableMap.of()));
driver.getDevTools().send(new Command("Profiler.start", ImmutableMap.of()));
//register to profiler events
driver.getDevTools().addListener(new Event("Profiler.consoleProfileStarted", ConsoleProfileStarted.class), new Consumer<Object>() {
@Override
public void accept(Object o) {
//do something
}
});
注意:在将Profiler域添加到Selenium Java客户端之前,您将必须提供Mapper.
Note: Until the Profiler domain will added to Selenium java client, you will have to supply your Mapper.
Outro
Outro
What is the difference between WebDriver and DevTool protocol
这篇关于Selenium WebDriver(java)可以与浏览器的检查工具元素选择器进行交互吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!