Setting proxy in RSelenium with PhantomJS

2019-05-11 07:28发布

问题:

I'm using the RSelenium library with the argument browserName = "phantomjs" in the remoteDriver command, however I was looking to run a test where I specify the type of the proxy server. I've seen that proxy authentication is possible in, e.g. Java, with the code used shown here:

ArrayList<String> cliArgsCap = new ArrayList<String>();
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);

Can the above be replicated in R?

回答1:

The following should work:

library(RSelenium)
pJS <- phantom(extras = c("--proxy=192.168.1.42:8080")
                           , "--proxy-auth=username:password"
                           , "--proxy-type=http")
)
remDr <- remoteDriver(browserName = "phantomjs")
remDr$open()