Search code examples
javaseleniumselenium-webdriverphantomjsghostdriver

How to set language to PhantomJs Ghostdriver with java?


I'm using PhantomJs Ghostdriver with Java to take some screenshots of the webpages. My problem is that PhantomJs are using locale from the host machine, so I need to set default language. I have found how to do it for Chrome Driver and for Firefox, but can't find the solution for Ghostdriver.

Any hints?


Solution

  • As per this issue and this pull request (and tested, of course):

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "it-IT");
    WebDriver driver = new PhantomJSDriver(caps );
    

    The constant above is at org.openqa.selenium.phantomjs.PhantomJSDriverService.PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX.

    Don't forget to change the language from it-IT to whatever you need.