Python + selenium webdriver: using authentication method

I am using python + selenium webdriver to automate checks. I am stuck on websites that request HTTP authentication through a popup.

I am trying to use the "authenticate" method with the following code:

#init.
driver = webdriver.Firefox()
driver.get(url)
#get to the auth popup window by clicking relevant link
elem = driver.find_element_by_id("login_link")
elem.click()
#use authenticate alert method
driver._switch_to.alert.authenticate("login", "password")

The (rare) information / document associated with this method indicates that it should provide the provided credentials and authenticate with http auth. This is not the case, and I get the following error:

File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/alert.py", line 105, authenticate self.driver.execute (Command.SET_ALERT_CREDENTIALS, {'username': username, 'password': password}) File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 201, execute self.error_handler.check_response (response) File "/ usr / local / lib / python2.7 / dist-packages / selenium / webdriver / remote / errorhandler.py ", line 159, in check_response raise exception_class (value) selenium.common.exceptions.WebDriverException: Message: Unrecognized command point / Sessions / c30d03e1-3835-42f5-ace0-968aef486b36 / alerts / credentials

is there something i don't see here / did someone come up on the same issue and resolve it?

PS: http://username:password@url .

+4
2

, / .

, Java, - - Browsermob RequestInterceptor, ( /URL-). , Basic auth, HTTP- Authorization ( "Basic" + Base64-encoded" user: pass 'string. , ' foo: bar ' Basic Zm9vOmJhcg==)

, - Selenium, , , - , , .

, , , user:pass@ URL-, , , , user:pass@, ( ) HTTP/HTTPS.

, Python?

Python Browsermob, REST API Python. REST, :

POST//[]/. HTTP-. , . json ( URL)

, ():

POST localhost:8787/proxy/<proxy_port>/headers '{"Authorization": "Basic Zm9vOmJhcg=="}'

- Python Twisted.

+2

URL-, :

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("network.http.phishy-userpass-length", 255)
driver = webdriver.Firefox(profile)
driver.get("http://admin:admin@the-internet.herokuapp.com/basic_auth")

, .

0

Source: https://habr.com/ru/post/1625912/


All Articles