I'm using Selenium and Appium to run my java project in Android mobile. I'm trying to execute on Chrome browser and every time it runs, it asks for proxy credentials (username and password), this is because I'm connected to a network with proxy.

I've tried several methods without success:

  • Passing credentials through the URL: http://username:[email protected]
  • Settings HTTP proxy through capabilities.

DesiredCapabilities capabilities = DesiredCapabilities.android(); Proxy proxy = new Proxy(); proxy.setHttpProxy(proxy+":"+port); proxy.setSocksUsername(user); proxy.setSocksPassword(pw); capabilities.setCapability("proxy", proxy);

  • Filling the popup fields changing the context to NATIVE_APP

driver.switchTo().window("NATIVE_APP"); driver.findElement(By.id("username")).sendKeys(user); driver.findElement(By.id("password")).sendKeys(pw); driver.findElement(By.id("button1")).click();

2 Answers 2


This is a trouble area currently. I will go thru your approaches one by one.

  • Passing credentials through the url: http://username:[email protected] This works only when the authentication model is HTTP basic. Moreover use of this kind of url is deprecated and not advisable.
  • Setting proxy thru capability will also not work as authentication is an argument to the New Session command not the user agent’s capabilities. Therefore, the authentication should be passed as a top-level parameter and not embedded in capabilities.

Coming to solution,

  • While navigating to the URL, create a uri with authentication included with that, so you dont have to perform authenticate fron UI side.
  • Use Alert.authenticateUsing(credentials...) from webdriver v3.1; now it is removed because of compliance. This might require you to down-grade the selenium version.

  • Or, Implement a similar api like mentioned above in the current version.

  • Or, this will be lil tricky; Extend the webdriver to override the creation of NewSession passing the credentials like below:

{ "user": "username", "password": "password", "capabilities": {…} }

I will comeback if i find an elegant solution.

  • This does not answer OP's question. Mar 13, 2018 at 16:42
  • The second part provides different solution options. Mar 14, 2018 at 5:41

I had to define the domain and username (which required an encoded backslash), password, address and port within the command when installing the Watir gem for Ruby...

Not sure how you'd run this with Appium, but hopefully it'll point you in the right direction.

gem install --http-proxy http://{domain}%5C{username}:{password}@{proxy.address}:{port}/ watir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.