Open austin-millan opened 3 years ago
Heyo, I'm encountering the same issues with a chromedriver browser. did you find a fix ?
Author is baka!
// this is work for me when using Chromedriver
caps.AddProxy(selenium.Proxy{
Type: selenium.Manual,
SOCKS: "localhost:1080", // this field should include port!!
// SocksPort: port, DO NOT SET THIS FIELD
SOCKSVersion: 5,
})
@Qingluan It doesn't work
it's working for me when using chromedriver. thx.
try setting selenium .HTTPClient. fix!
func NewRemote(ctx context.Context) (selenium.WebDriver, error) {
caps := selenium.Capabilities{"browserName": "chrome"}
var args []string
args = append(args, "--no-sandbox")
caps.AddChrome(chrome.Capabilities{
Args: args,
})
selenium.HTTPClient = ProxyClient()
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", 8080))
if err != nil {
return nil, err
}
return wd, err
}
func ProxyClient() *http.Client {
httpProxy := os.Getenv("HTTP_PROXY")
if httpProxy == "" {
return &http.Client{}
}
proxyUrl, err := url.Parse(httpProxy)
if err != nil {
return &http.Client{}
}
client := &http.Client{Transport: &http.Transport{
Proxy: http.ProxyURL(proxyUrl),
}}
return client
}
selenium.HTTPClient = ProxyClient()
What should be written at HTTP_PROXY?
try setting selenium .HTTPClient. fix!
func NewRemote(ctx context.Context) (selenium.WebDriver, error) { caps := selenium.Capabilities{"browserName": "chrome"} var args []string args = append(args, "--no-sandbox") caps.AddChrome(chrome.Capabilities{ Args: args, }) selenium.HTTPClient = ProxyClient() wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", 8080)) if err != nil { return nil, err } return wd, err } func ProxyClient() *http.Client { httpProxy := os.Getenv("HTTP_PROXY") if httpProxy == "" { return &http.Client{} } proxyUrl, err := url.Parse(httpProxy) if err != nil { return &http.Client{} } client := &http.Client{Transport: &http.Transport{ Proxy: http.ProxyURL(proxyUrl), }} return client }
@rudy-tao it doesn't work
Version Info
Using only HTTP field
This configuration uses only the HTTP field of the
selenium.Proxy
struct. When creating a new selenium service with this configuration it does not run into errors, but the proxy isn't actually used in requests.Using HTTP field and port
Specifying the HTTP port and IP (separately) causes error when creating new remote:
SOCKS5
Note the same things happen with SOCKS5 Proxy configuration, except there's also an issue when specifying the
proxy.SOCKSVersion
, something about casting a long to an int in Java.