RSelenium behind proxy
Asked Answered
A

2

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

Angelo answered 17/5, 2018 at 9:43 Comment(4)
What kind of proxy? Http proxy? Socks proxy?Allman
@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 + passwordAngelo
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?Hickman
@Angelo did any of the methods provided here work for you?Scrawl
A
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

Allman answered 21/5, 2018 at 7:22 Comment(2)
unfortunately navigate() still prints a NULL on the consoleAngelo
Navigate is suppose to return null only, i think get current url should work. I had tested on R3.5Allman
E
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.

Eam answered 20/6, 2019 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.