简体   繁体   中英

Selenium-webdriver Proxy Authentication

Currently, I need to use proxy with authentication, on selenium-webdriver on Firefox.

I successfully connect to Tor using:

var option = new Options();
  option.headless()
  option.setPreference('network.proxy.type', 1)
  .setPreference('network.proxy.socks', '127.0.0.1')
  .setPreference('network.proxy.socks_port', 9050)
  .setPreference('network.proxy.socks_remote_dns', true)
  .setPreference('network.proxy.socks_version', 5)


  let driver = await new Builder()
  .forBrowser(Browser.FIREFOX)
  .setFirefoxOptions(option)
  .build();

But I don't find how to pass username and password for other proxy.

I looked on Selenium's github, but nothing worked. This is the exemple on the file's comment but not working:

let capabilities = new Capabilities();
  capabilities.setProxy(proxy.socks('username:pass@host:port'))
  // for tor
  capabilities.setProxy(proxy.socks('host:port'))

  let driver = await new Builder()
  .withCapabilities(capabilities)
  .forBrowser(Browser.FIREFOX)
  .setFirefoxOptions(option)
  .build();

Please help me:(

You could try using the following with setPreference itself:

.set_preference("network.proxy.socks_username", USERNAME)
.set_preference("network.proxy.socks_password", PASSWORD)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM