The two ways to use HTTP authentication in Selenium with passwords which contain special characters like @ are
HTTP Authentication Methods
JavaScript Injection
Using JavaScript injection, you would set the credentials after loading the page instead of including them in the URL; this helps you avoid having problems with special characters inside the password.
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.stagesite.com')
driver.execute_script("document.getElementById('username').value = 'user';")
driver.execute_script("document.getElementById('password').value = 'your@password';")
driver.execute_script("document.querySelector('form').submit();")
Custom Proxy
Authentication management using a proxy like BrowserMob Proxy can be managed without changing the URL, and it is very helpful for capturing network traffic and managing complex authentication scenarios.
BrowserMob Proxy Setup
Start the proxy server.
Configure Selenium to use the proxy.
BrowserMobProxyServer proxy = new BrowserMobProxyServer();
proxy.start(0);
int port = proxy.getPort();
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
WebDriver driver = new ChromeDriver(capabilities);
With such a configuration, you could permit HTTP requests and responses that were accompanied by efficient authentication.
Encoding URLs
If you do accept the URL method of encoding, you should encode the special characters within it carefully. For example, this character: @ should be represented as %40:
url = "http://user:your%[email protected]"
Encoded in this way allows the browser to read them as being part of your password thereby eliminating any eventual complications which may arise by the existence of special characters.