如何从 selenium webdriver 中启用 chromedriver 详细日志记录功能?
我找到了合适的方法loggingTo
and enableVerboseLogging
但似乎无法正确使用它们:
require('chromedriver');
const webdriver = require('selenium-webdriver');
let capabilities = webdriver.Capabilities.chrome();
capabilities.setScrollBehavior(1);
let builder = new webdriver.Builder().withCapabilities(capabilities);
builder.enableVerboseLogging(); // fails!!!
let driver = builder.build();
在评论中chrome.js https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/chrome.js,有一种方法可以为 chrome webdriver 启用日志记录
*
* By default, every Chrome session will use a single driver service, which is
* started the first time a {@link Driver} instance is created and terminated
* when this process exits. The default service will inherit its environment
* from the current process and direct all output to /dev/null. You may obtain
* a handle to this default service using
* {@link #getDefaultService getDefaultService()} and change its configuration
* with {@link #setDefaultService setDefaultService()}.
*
* You may also create a {@link Driver} with its own driver service. This is
* useful if you need to capture the server's log output for a specific session:
*
* let chrome = require('selenium-webdriver/chrome');
*
* let service = new chrome.ServiceBuilder()
* .loggingTo('/my/log/file.txt')
* .enableVerboseLogging()
* .build();
*
* let options = new chrome.Options();
* // configure browser options ...
*
* let driver = chrome.Driver.createSession(options, service);
*
您还有其他选择:
由于 ChromeDriver 实现了有线协议,因此它与任何 RemoteWebDriver 客户端完全兼容。只需使用参数启动 ChromeDriver 可执行文件(用作服务器)--log-path
and --verbose
,创建一个客户端,然后就可以了:
WebDriver driver = new RemoteWebDriver(
"http://localhost:9515",
DesiredCapabilities.chrome()
);
driver.get("http://www.google.com");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)