[英]how to handle alerts in selenium with phantomjs headless browser
[英]Selenium - set headers in headless browser
我正在嘗試在無頭瀏覽器上運行一個簡單的測試。 在我的示例測試中,當我截取屏幕截圖時,訪問登台網站時只會出現空白屏幕,但是生產網站(例如http://www.google.co.uk)可以正常工作。 所以我想我們需要設置標題以便訪問我們的暫存區嗎?
有誰知道如何針對無頭瀏覽器在硒上執行此操作?
我的代碼是:
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");
}
==================================================
更新
通過閱讀這篇文章找到了解決方案: PhantomJSDriver適用於HTTP但不適用於HTTPS
我沒有親自測試過,但是GhostDriver文檔在https://github.com/detro/ghostdriver#what-extra-webdriver-capabilities-ghostdriver-offers中具有以下內容
phantomjs.page.customHeaders.HEADER = VALUE-加載URL時添加額外的HTTP標頭
從PR: 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");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.