7

I am trying to use RSelenium. Here is what I am doing:

library(RSelenium)  
driver<- rsDriver(browser=c("chrome"))
remDr <- driver[["client"]]
remDr$open()

returns
$id
[1] NA

remDr$navigate("http://www.google.com")

(returns NULL)

remDr$getCurrentUrl()

returns empty list

I am thinking this disappointing result might be because I am behind corporate proxy.

How can I pass the http proxy to selenium browser?

Thank you

RockScience
  • 17,932
  • 26
  • 89
  • 125
  • What kind of proxy? Http proxy? Socks proxy? – Tarun Lalwani May 21 '18 at 05:47
  • @TarunLalwani http/https. I usually just pass the ip and port, but given that here the Selenium browser may not be running under my windows login, I will certainly also have to pass my login + password – RockScience May 21 '18 at 06:00
  • you won't be able to pass your username and password, as you, most probably, have an AD/LDAP login, which is not a typical basic auth. Can you please add verbose=TRUE to rsDriver and attach the log somewhere OR start the standalone server and show the output when this happens? – Stan E May 28 '18 at 03:16
  • @RockScience did any of the methods provided here work for you? – stevec Nov 10 '20 at 01:45

2 Answers2

9

You need to use extraCapabilities and set the proxy using the same

cprof <- list(chromeOptions = 
                  list(args = list("--proxy-server=http://118.69.61.212:53281")))

driver<- rsDriver(browser=c("chrome"), extraCapabilities = cprof)
driver$client$navigate("http://ipinfo.io")

And you can see that chrome now uses the proxy config

Chrome proxy

Tarun Lalwani
  • 142,312
  • 9
  • 204
  • 265
2

I use RSelenium with Docker.

Here is mine option:

# connect to docker. 
# need to run in terminal (ctrl + alt + enter)
docker run -d -p  4445:4444 selenium/standalone-chrome:3.5.3
eCap <- list(chromeOptions = 
             list(args = list("--proxy-server=http://47.254.69.158:9999")))
remDr <- remoteDriver(remoteServerAddr = "localhost",
                  port = 4445L,
                  browserName = "chrome",
                  extraCapabilities = eCap)
remDr$open()
remDr$navigate("https://ipinfo.io/")
remDr$screenshot(display = TRUE)

So i got this this

If you still have troubles try to switch to other proxy and/or reload Docker.

Hope this will be usefull.

ElvinFox
  • 71
  • 2
  • 7