2016-11-11 50 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"); 
相關問題