Shoaib Akhtar
Shoaib Akhtar

Reputation: 1403

How to pass special character in URL in windows authentication?

To handle windows authentication, one way to handle such scenario is by passing credentials in URL itself as shown below

driver.get('http://username:[email protected]')

But in my case since password contains special character, like 'password@123', so now code contains double special character '@' as shown below

driver.get('http://username:password@[email protected]')

I tried replacing '@' with '%40' using url encoder/decoder, but it's not working. I am working with python selenium, any idea how to handle such scenario?

Upvotes: 2

Views: 3040

Answers (3)

innicoder
innicoder

Reputation: 2690

A simple raw string will do the job, note that I use triple quotes just for escaping any possible errors with ' and ".

driver.get(r'''http://username:password@[email protected]''')

Upvotes: 2

edixon
edixon

Reputation: 1000

If your username is 'shoaib' and your password is akhtar@123 then your .get() invocation should be:

driver.get('http://shoaib:akhtar%[email protected]')

Upvotes: 0

Aditya Gaurav
Aditya Gaurav

Reputation: 78

Can you please try out with the below syntax:

String url =  http://username:password%[email protected];
driver.get(url);

In one of the application, we have more than one @ character in the password. I'm simply escaping the @ character. For example

URL: http://username:password@#@@sample.com
Encoded_URL:  http://username:password%40%23%[email protected]

and then try to browse the encoded URL.

driver.get(Encoded_URL);

For me, it is working fine. Please let me know if it works for you.

Upvotes: 0

Related Questions