如何确保我的应用程序在selenium中使用代理服务器而不是我的IP地址?

时间:2017-07-23 21:26:55

标签: java selenium proxy phantomjs

我正在使用Selenium和PhantomJS浏览器。我已经设置了如下代理:

DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setJavascriptEnabled(true);
System.setProperty("phantomjs.binary.path", "../Drivers/phantomjs.exe");

ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--proxy=hostname:port");
cliArgsCap.add("--proxy-auth=username:password");
cliArgsCap.add("--proxy-type=http");
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);

driver = new PhantomJSDriver(capabilities);

我的应用程序运行正常。但是如何验证我的应用程序是否正在使用我设置的代理?

2 个答案:

答案 0 :(得分:0)

您可以在本地使用fiddlersetup a proxy server,然后将您的selenium代理配置更改为您已设置的代理。让我们运行你的应用程序,如果你的应用程序将抛出代理,那么fiddler将抓住它。

答案 1 :(得分:0)

在运行主脚本之前,请向显示客户当前IP的http://api.ipify.org/发出请求,并检查代码是否为您的IP或代理IP。