如何使用selenium在PhantomJS中设置代理身份validation?
我在java中运行这个简单的selenium测试:
public static void main(String[] args){ WebDriver driver = new PhantomJSDriver(); driver.get("http://www.google.com"); WebElement element = driver.findElement(By.id("gbqfif")); element.sendKeys("cheese"); element.submit(); System.out.println("Titulo:"+driver.getTitle()); driver.quit(); }
但在我的办公室,它需要代理身份validation,我不知道如何设置它。
我必须把我的用户和密码放在某个地方。
你能帮我吗?
PhantomJS使用从命令行( docs )设置的三个代理选项。
--proxy=address:port
指定要使用的代理服务器(例如--proxy=192.168.1.42:8080
)。--proxy-type=[http|socks5|none]
指定代理服务器的类型(默认为http
)。--proxy-auth
指定代理的身份validation信息,例如--proxy-auth=username:password)
。
要使用它们,您必须将它们添加到DesiredCapabilities地图(如本答案中所示):
ArrayList cliArgsCap = new ArrayList (); cliArgsCap.add("--proxy=address:port"); cliArgsCap.add("--proxy-auth=username:password"); cliArgsCap.add("--proxy-type=http"); DesiredCapabilities capabilities = DesiredCapabilities.phantomjs(); capabilities.setCapability( PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap); WebDriver driver = new PhantomJSDriver(capabilities);
- 如何在JPA和Hibernate 4.3中使用SchemaExportTool
- Java Swing – KeyListener
- 为什么inheritance是强耦合的,因为组合在Java中松散耦合?
- 为什么autoimport只有java.lang包?
- Java 7.x中的validateTree不起作用(在Java 6.x中很好)
- 在JScrollPane中获取显示的组件
- 如何使用java按上次更新时间排序SFTP文件?
- 想要使用带有32字节的AES 256 CBC,但它显示了java.security.InvalidAlgorithmParameterException
- 如何使用Apache Poi更改工作表的选项卡颜色