如何从 selenium webdriver 中启用 chromedriver 详细日志记录功能?
我找到了合适的方法 loggingTo
和 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的评论中, 有一种方法可以为 chromewebdriver 启用日志记录
*
* 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 作为独立进程运行
由于 ChromeDriver 实现了有线协议(protocol),因此它与任何 RemoteWebDriver 客户端完全兼容。只需使用参数 --log-path
和 --verbose
启动 ChromeDriver 可执行文件(作为服务器工作),创建一个客户端,然后就可以了:
WebDriver driver = new RemoteWebDriver(
"http://localhost:9515",
DesiredCapabilities.chrome()
);
driver.get("http://www.google.com");
关于javascript - 如何启用 chromedriver 从 selenium webdriver 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42803545/