Eugene S
Eugene S

Reputation: 6900

Headless/GUIless automation with Selenium Webdriver

I would like to save some resources on my low-spec Windows boxes by running the browser in a headless mode. As far as I am aware, 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. Specifically, the following exception is returned:

[ERROR - 2016-08-01T04:24:24.894Z] RouterReqHand - _handle.error - {"name":"Invalid Command Method"," . . . "}

as a result of not supporting getAlertText WebDriver Command when performing:

Alert alert = driver.switchTo().alert();

and specifically this method implemented in EventFiringWebDriver:

public Alert alert() {
  return targetLocator.alert();
}

I am looking for an alternative approach or a feasible workaround. Anyone?

Upvotes: 0

Views: 776

Answers (1)

Eugene S
Eugene S

Reputation: 6900

I have been able to work around that by executing the alert handling using JavaScript directly like this:

JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("window.alert = function(){}");
jsExecutor.executeScript("window.confirm = function(){return true;}");

At the moment, there seem to be no way to perform that operation directly via WebDriver interface for PhantomJS.

Upvotes: 2

Related Questions