Selenium 4 alpha中的sendDevToolsCommand [英] sendDevToolsCommand in Selenium 4 alpha

查看:342
本文介绍了Selenium 4 alpha中的sendDevToolsCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据此文章 ,Selenium 4 alpha有一个 sendDevToolsCommand ,它会向浏览器发送一个任意的DevTools命令,并返回一个将在命令完成后解决的诺言:

According to this article, Selenium 4 alpha has a sendDevToolsCommand that sends an arbitrary DevTools command to the browser and returns a promise that will be resolved when the command has finished:


为chrome.Driver添加了 sendDevToolsCommand和 setDownloadPath。

Added "sendDevToolsCommand" and "setDownloadPath" for chrome.Driver.

但我似乎找不到如何使用它。听起来有点像在Selenium中使用JavaScript执行器。

But I can't seem to find how to use it. It sounds a bit like using JavaScript executor in Selenium.

有人可以提供示例用法吗?我正在使用Selenium + Java。

Can someone provide an example usage? I'm using Selenium + Java.

推荐答案

在Chrome驱动程序中添加了调用devtool api的命令。

The command to call the devtool api was added a few years back in the Chrome driver.

即使该方法尚不存在,您也可以将其与Selenium一起使用:

You can already use it with Selenium even if the method is not yet present:

  • Take full page screenshot
  • Print To PDF
  • Inject some Javascript before the page loads
  • Block a network URL
  • Save/restore the cookies for all domains
  • Get transparent screenshot

此命令可让您访问 devtools api ,ChromeDriver在内部使用它来驱动浏览器

This command gives you access to the devtools api, which is used by ChromeDriver internally to drive the browser.

该方法将命令名称作为第一个参数,并将参数字典作为第二个参数。要弄清楚如何调用命令,请在搜索中添加 puppeteer 。例如人偶设置下载位置

The method takes the name of the command as first argument and a dictionary of parameters as second argument. To figure out how to call a command, add puppeteer in your searches. For instance puppeteer set download location.

请注意, executeCdpCommand 是在Java master分支中实现的,因此在下一发行版中应该可用。

Note that executeCdpCommand is implemented in the Java master branch, so it should be available in the next release.

这篇关于Selenium 4 alpha中的sendDevToolsCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆