[🐛 Bug]: Unable to launch url in Selenium-automated Firefox browser due to temp user profile copy
What happened?
My desktop app redirects user to a login screen on Firefox, and I want to automate it using Selenium. My current workflow:
- Launch Selenium-controlled Firefox browser using GeckoDriver
- Click on "Login" button on my desktop app. The desktop app launches the login screen on user's OS default browser using the default user profile (in which case I set in profiles.ini to the temp profile copy created by Selenium).
- (ERROR) Popup on the error below is displayed
Firefox is already running, but is not responding. The old Firefox process must be closed to open a new window.
How can we reproduce the issue?
## Testcase
import configparser
import os
web_driver = selenium_webdriver.Firefox(executable_path='C:\\Users\\mnxl\\.wdm\\drivers\\geckodriver\\win64\\v0.34.0\\geckodriver')
profile = web_driver.capabilities['moz:profile']
Path to the Firefox profiles folder
profiles_path = os.path.expanduser(r'~\AppData\Roaming\Mozilla\Firefox')
Path to the profiles.ini file
profiles_ini_path = os.path.join(profiles_path, 'profiles.ini')
Read the profiles.ini file
config = configparser.ConfigParser()
config.read(profiles_ini_path)
Find the section for the profile to set as default
for section in config.sections():
if config.has_option(section, 'Path') and config.get(section, 'Path') == profile:
# Set this profile as the default
config.set(section, 'Default', '1')
else:
# Set all other profiles as not default
config.set(section, 'Default', '0')
Write the changes back to the profiles.ini file
with open(profiles_ini_path, 'w') as configfile:
config.write(configfile)
### Operating System
Win 11
### Selenium version
Python Selenium 3.141.0
### What are the browser(s) and version(s) where you see this issue?
Firefox 125.0.3
### What are the browser driver(s) and version(s) where you see this issue?
GeckoDriver 0.34.0 (Installed with GeckoDriverManager
### Are you using Selenium Grid?
No.
@MagdelineNg, thank you for creating this issue. We will troubleshoot it as soon as we can.
Info for maintainers
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template label.
If the issue is a question, add the I-question label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable G-* label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer label.
Thank you!
Referred to these issues on Selenium creating a temporary user profile copy, but this creates a problem for apps that use default user profile to launch a url in browser as the url cannot be launched in the existing Selenium browser for automation purposes. https://stackoverflow.com/questions/69448781/selenium-throws-error-if-an-instance-of-firefox-is-already-open https://stackoverflow.com/questions/40521731/why-selenium-always-create-temporary-firefox-profiles-using-web-driver
I don't know how Selenium can help here. You are manipulating a profile being used, and I wonder if Firefox plays well with that.
For testing purposes, somehow your desktop app needs to know to which Firefox instance it has to connect for the validation. You should also explore if there is a way to mock that interaction. In any case, this is more about how to automate a flow rather than an issue in Selenium.
Please ask questions using the different options below.
💬 Please ask questions at:
- 📫 The Selenium user group
- 📮 StackOverflow
- 🗣 Our IRC/Slack/Matrix channels where the community can help you as well
@diemol I raised an issue in Geckodriver here https://github.com/mozilla/geckodriver/issues/2179#issuecomment-2095912418 , but I believe it may be related to Selenium Firefox webdriver options. I am not sure how to remove the options set by Selenium webdriver by default, such as -no-remote , and also how to set Firefox environment variables(such as MOZ_MARIONETTE) in the script as well
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.