How to enter the username and password of the proxy when starting Firefox on Selenium in Python

Asked 1 years ago, Updated 1 years ago, 328 views

When starting Firefox with Selenium in Python, you are asked to enter the username and password of the proxy as shown in the image below. Could you tell me how to enter this from the Python script?

Enter a description of the image here

My execution environment

Ubuntu 18.04.3 LTS
Python 3.9.1
selenium3.141.0 py39h07f9747_1002conda-forge
geckodriver 0.29.0 (2021-01-14, cf6956a5ec8e)

The Python script I ran is as follows.

#proxy username and password
USERNAME="suzuki"
PASSWORD="hoge"

from selenium import webdriver
from time import sleep

browser=webdriver.Firefox(executable_path=r'~/path_to_driver/geckodriver')
sleep(5)

# After starting the browser on the following two lines, I entered USERNAME, TAB key, and PASSWORD, and pressed the OK button, but it doesn't respond at all.
browser.switch_to.alert.send_keys (USERNAME+u'\ue004'+PASSWORD) 
browser.switch_to.alert.accept()

If you execute the above code, the Firefox browser will stand up and ask for the Proxy username and password, but nothing will be entered.The following error message appears on the terminal:
selenium.common.exception.NoAlertPresentException message
Does it mean that the proxy input pop-up is not recognized as an alert?

I made the last two lines by referring to the answers below.
https://stackoverflow.com/a/57220686/10432875

How to enter the tab (u'\ue004') is
https://qiita.com/KI1208/items/effe553d1ce9a9d04d76
I referred to the .

I look forward to hearing from you.

python3 ubuntu selenium firefox selenium-webdriver

2022-09-30 21:55

1 Answers

There is no environment to try, so I just looked it up with keywords, but one of the answers to similar questions in the English version of SO is
The following methods were introduced:

Using a http proxy with headless Firefox in Selenium webdriver in Python-Stack Overflow

 from selenium.webdriver.common.proxy import Proxy, ProxyType

myProxy="username:password@proxyDomain:proxyPort"

proxy=Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': myProxy,
    'ftpProxy': myProxy,
    'sslProxy': myProxy,
    'noProxy': '# set this value as desired
    })

driver=webdriver.Firefox(firefox_binary=binary, proxy=proxy)


2022-09-30 21:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.