0

i have been wondering for a while a way to provide proxy credentials for phantomJs in selenium webdriver in java after my own course of research i thought it is done but nevertheless i am still receiving 407(proxy issue) i have provided my code below for your kind review, help would be greatly appriciated

     public class PhantomProxy {

         private static PhantomJSDriverService service;  
         private static WebDriver webDriver;  
         protected static DesiredCapabilities dCaps;  
         public static void main(String[] args) {
             String[]a={"--proxy=ip:10....(your proxy ip)","--proxy-auth=username:password"};
            service = new PhantomJSDriverService.Builder()  
            .usingPhantomJSExecutable(new File("your own custom path\\phantomjs.exe"))  
            .usingCommandLineArguments(a).usingPort(6050).build();  

           service.start();  

                Capabilities caps = new DesiredCapabilities();
                    ((DesiredCapabilities) caps).setJavascriptEnabled(true);                
                    ((DesiredCapabilities) caps).setCapability("takesScreenshot", true);  

                    webDriver = new RemoteWebDriver(service.getUrl(), caps);  
                    webDriver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 

                    webDriver.get("http://www.google.com");
                     Thread.sleep(2000L);
                     String pageSource=webDriver.getPageSource();
                       System.out.println(pageSource);
                      webDriver.quit();      
    }

it is to be noted that the command line arguments works fine in command line interface but i completely have no idea why it doesn't works here

0

1 Answer 1

0

Here is a part of code that works for me with phantomJs 2.0.0 on windows

private static void phantomJsDriver() {
    final String pathToPhantom = phantomJsPath();
    DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
      capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, pathToPhantom);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCapabilities());
    driver = new PhantomJSDriver(capabilities);
}

private static List<String> cliArgsCapabilities() {
    List<String> cliArgsCap = new ArrayList<String>();
    cliArgsCap.add("--proxy=url:port");
    cliArgsCap.add("--proxy-auth=user:pass");
    cliArgsCap.add("--proxy-type=http");
    return cliArgsCap;
}

You just need to changes lines with you own values for proxy

cliArgsCap.add("--proxy=url:port");
cliArgsCap.add("--proxy-auth=user:pass");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.