3

I have a very specific problem when trying to use default Selenium auth using this construction username:password@siteurl.com
So here is an issue: if I use a password like this "''asd'asd';123asd' (with specific symbols) traceback will say that URL is incorrect. But if the password is just with numbers and letters -- everything is OK. Below is an example of a code that works correctly but for my example, I need to fill password with a lot of specific symbols and I don't have permission to change it.

import unittest
from selenium import webdriver


class LoggedTest(unittest.TestCase):
    @classmethod
    def setUp(inst):
        # create a new Chrome session """
        inst.driver = webdriver.Chrome()
        inst.driver.implicitly_wait(30)
        inst.driver.maximize_window()

        # navigate to the application home page """
        inst.driver.get("http://admin:admin@theinternet.herokuapp.com/basic_auth")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Ivan Pelykh
  • 33
  • 1
  • 5
  • Try `driver.get('http://admin:%22%27%27asd%27asd%27%3B123asd%27@theinternet.herokuapp.com/basic_auth')`. You can use [URL-encoder](https://meyerweb.com/eric/tools/dencoder/) to encode/decode special characters – Andersson Nov 19 '18 at 09:22
  • This case work too, thanks. So main issue was with UTF encoding, now I know how to play with that. Thanks a lot. – Ivan Pelykh Nov 19 '18 at 09:27

1 Answers1

6

For Basic Authentication if the Password contains symbols e.g. "''asd'asd';123asd' you need to translate the string into UTF. As an example:

username = "%21%40user" #stands for !@user
password = "%0D%0Apass" #stands for ^&pass
webpage = "something.url.com"

Now you can use:

url = 'http://{}:{}@{}'.format(username, password, webpage)
driver.get(url)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352