1

I just added the two lines related about proxy

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", true);
caps.setCapability("screen-resolution", "1280x1024");
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Users\\USERNAME\\Downloads\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe");
caps.setCapability("proxy", "127.0.0.1:1024"); //added this line
caps.setCapability("proxy-type", "socks"); //and this line
Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF);

driver = new PhantomJSDriver(caps);

But now I get the following error when I run the program

[INFO  - 2015-08-04T00:34:45.924Z] GhostDriver - Main - running on port 15821
[ERROR - 2015-08-04T00:34:46.845Z] RouterReqHand - _handle.error - {"stack":"\tat _getProxySettingsFromCapabilities (:/ghostdriver/session.js:131:41)\n\tat Session (:/ghostdriver/session.js:165:62)\n\tat _postNewSessionCommand (:/ghostdriver/request_handlers/session_manager_request_handler.js:75:49)\n\tat _handle (:/ghostdriver/request_handlers/session_manager_request_handler.js:44:35)\n\tat _handle (:/ghostdriver/request_handlers/router_request_handler.js:70:37)","line":131,"sourceURL":":/ghostdriver/session.js"}

  :262 in error
[INFO  - 2015-08-04T00:34:46.861Z] ShutdownReqHand - _handle - About to shutdown
Aug 03, 2015 8:34:47 PM org.openqa.selenium.os.UnixProcess$SeleniumWatchDog destroyHarder
INFO: Command failed to close cleanly. Destroying forcefully (v2). org.openqa.selenium.os.UnixProcess$SeleniumWatchDog@7e1d83ab
org.openqa.selenium.UnsupportedCommandException: TypeError - undefined is not an object (evaluating 'proxyCapability["proxyType"].toLowerCase')

What I am doing wrong?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Arya
  • 8,473
  • 27
  • 105
  • 175

1 Answers1

2

I have figured it out, here is how it's for whoever that runs into the same question

ArrayList<String> cliArgsCap = new ArrayList<String>();
cliArgsCap.add("--proxy=127.0.0.1:1024");
// cliArgsCap.add("--proxy-auth=username:password");
cliArgsCap.add("--proxy-type=socks5");

DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", true);
caps.setCapability("screen-resolution", "1280x1024");
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\Users\\USER\\Downloads\\phantomjs-2.0.0-windows\\bin\\phantomjs.exe");

caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);

Logger.getLogger(PhantomJSDriverService.class.getName()).setLevel(Level.OFF);

driver = new PhantomJSDriver(caps);
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Arya
  • 8,473
  • 27
  • 105
  • 175