2016-11-11 51 views
0

我试图在无头浏览器上运行一个简单的测试。 在我的示例测试中,当我截取屏幕截图时,只是在访问我的临时网站时出现空白屏幕,但生产网站(如http://www.google.co.uk)正常工作。所以我想我们需要设置标题才能访问我们的舞台?Selenium - 在无头浏览器中设置标题

有没有人知道如何做到这一点在硒无头浏览器?

我的代码是:

public void testPhantom() throws IOException { 
    DesiredCapabilities caps = new DesiredCapabilities(); 
    caps.setJavascriptEnabled(true); 
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "phantomjs"); 
    Webdriver driver = new PhantomJSDriver(caps); 

    open("https://mywebsite.staging.com/"); 
    takeAScreenshot("Website"); 
} 

================================= =================

UPDATE

发现阅读这篇文章的解决方案:PhantomJSDriver works for HTTP but not for HTTPS

回答

0

我没有这个亲自测试,但GhostDriver文档在https://github.com/detro/ghostdriver#what-extra-webdriver-capabilities-ghostdriver-offers

phantomjs.page.customHeaders.HEADER = VALUE - 加载URL

而且从PR时添加额外的HTTP标头:https://github.com/detro/ghostdriver/pull/229

PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX = "phantomjs.page.customHeaders."; //< notice the dot at the end 
capabilities.setCapability(PHANTOMJS_PAGE_CUSTOMHEADERS_PREFIX + "Accept-Language", "it-IT"); 
相关问题