[英]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.