Headless/GUIless 使用 Selenium Webdriver 实现自动化
Headless/GUIless automation with Selenium Webdriver
我想通过 运行 无头模式的浏览器在我的低规格 Windows 盒子上保存一些资源。据我所知,PhantomJS + GhostDriver is the standard choice for such task to be used with Selenium Webdriver. However after trying it and immediately running into issues with alerts handling which doesn't seem to be supported by PhantomJS。具体返回如下异常:
[ERROR - 2016-08-01T04:24:24.894Z] RouterReqHand - _handle.error - {"name":"Invalid Command Method"," . . . "}
由于不支持 getAlertText
WebDriver Command
执行时:
Alert alert = driver.switchTo().alert();
特别是此方法在 EventFiringWebDriver
中实现:
public Alert alert() {
return targetLocator.alert();
}
我正在寻找替代方法或可行的解决方法。有人吗?
我已经能够通过直接使用 JavaScript 执行警报处理来解决这个问题:
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("window.alert = function(){}");
jsExecutor.executeScript("window.confirm = function(){return true;}");
目前,似乎无法通过 PhantomJS 的 WebDriver
界面直接执行该操作。
我想通过 运行 无头模式的浏览器在我的低规格 Windows 盒子上保存一些资源。据我所知,PhantomJS + GhostDriver is the standard choice for such task to be used with Selenium Webdriver. However after trying it and immediately running into issues with alerts handling which doesn't seem to be supported by PhantomJS。具体返回如下异常:
[ERROR - 2016-08-01T04:24:24.894Z] RouterReqHand - _handle.error - {"name":"Invalid Command Method"," . . . "}
由于不支持 getAlertText
WebDriver Command
执行时:
Alert alert = driver.switchTo().alert();
特别是此方法在 EventFiringWebDriver
中实现:
public Alert alert() {
return targetLocator.alert();
}
我正在寻找替代方法或可行的解决方法。有人吗?
我已经能够通过直接使用 JavaScript 执行警报处理来解决这个问题:
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("window.alert = function(){}");
jsExecutor.executeScript("window.confirm = function(){return true;}");
目前,似乎无法通过 PhantomJS 的 WebDriver
界面直接执行该操作。