java 如何使用代理启动 selenium 浏览器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9884804/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to start selenium browser with proxy
提问by Khoyendra Pande
I am trying to start selenium and selenium's browser with proxy but not getting success. I have used two methods:
我正在尝试使用代理启动 selenium 和 selenium 的浏览器,但没有成功。我使用了两种方法:
Properties sysProps = System.getProperties();
sysProps.put("proxySet", "true");
sysProps.put("proxyHost", "190.249.188.220");
sysProps.put("proxyPort", "81");
and
和
java -jar lib/selenium-server.jar proxyHost=22.52.50.228 proxyPort=80
but both are not supporting.
但两者都不支持。
is anyone able to help me to start selenium's browser with proxy.
任何人都可以帮助我使用代理启动 selenium 的浏览器。
采纳答案by Alex Stybaev
try
尝试
java -Dhttp.proxyHost=HOSTNAME -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USER -Dhttp.proxyPassword=PASSWORD -jar selenium-server.jar
java -Dhttp.proxyHost=HOSTNAME -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USER -Dhttp.proxyPassword=PASSWORD -jar selenium-server.jar
* Dhttp.proxyHost – proxy IP address
* Dhttp.proxyPort – proxy port
* Dhttp.proxyUser – user name if HTTP-proxy authentication required;
* Dhttp.proxyPassword – user password if HTTP-proxy authentication required.
回答by Hai Nguyen
You can use this:
你可以使用这个:
String PROXY = "localhost:8080";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new InternetExplorerDriver(cap);
For more detail, refer here
有关更多详细信息,请参阅此处