6

In the documentation, I read that for using proxy set while building driver like this:

var driver = new webdriver.Builder()
    .withCapabilities(webdriver.Capabilities.chrome())
    .setProxy(proxy.manual({http: 'host:1234'}))
    .build();

When I use this code with proxy '103.87.16.2:80' - .setProxy(proxy.manual({http: 'host:1234'})), I still have my home IP.

What is the problem?

Omar Einea
  • 2,478
  • 7
  • 23
  • 35
chosirai
  • 193
  • 3
  • 7
  • The proxy works as expected. How are you determining the IP address in use? Also, please have a look at https://stackoverflow.com/questions/11450158/how-do-i-set-proxy-for-chrome-in-python-webdriver and https://sites.google.com/a/chromium.org/chromedriver/capabilities – rollstuhlfahrer Mar 25 '18 at 20:13

1 Answers1

3
const { Builder } =  require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

let proxyAddress = '212.56.139.253:80'
// Setting the proxy-server option is needed to info chrome to use proxy
let option = new chrome.Options().addArguments(`--proxy-server=http://${proxyAddress}`)

const driver = new Builder()
  .forBrowser('chrome')
  .setChromeOptions(option)
  .build()

driver.get('http://whatismyip.host/')
  .then(() => console.log('DONE'))
Joshua Ugba
  • 101
  • 1
  • 6
  • 2
    Thank you for this code snippet, which might provide some limited, immediate help. A [proper explanation](https://meta.stackexchange.com/q/114762/349538) would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please [edit] your answer to add some explanation, including the assumptions you’ve made. – Şivā SankĂr Feb 17 '19 at 13:52
  • Thanks for the feedback, I modeled the response as close to the context of the question as possible. I have added a single line comment to explain the only new thing I added. – Joshua Ugba Feb 17 '19 at 14:48
  • Works perfectly. I tried for 2 hours with firefox to add proxy but didn't worked at all, – Code Cooker Jun 24 '20 at 06:19
  • do you know how to use proxy which also has username and password? i tried to add it at the end of the string but it does now work –  Oct 30 '22 at 13:33