Trying to find a way to switch the active profile in a Selenium Firefox driver. This question about multiple Firefox profiles states that creating and using multiple profiles is possible. However, it would be better if there were some way to switch the active Firefox profile within the driver session - instead of starting a new one.
How can I switch the active Firefox profile with Selenium?
Thanks very much!
You can't. Selenium does not let you change Firefox profiles, and I'm pretty sure even Firefox doesn't.
Related
I need to login to multiple accounts (same website) at once and I need to open multiple tabs.
Each tab needs to be independent so that I can login to different accounts.
is there any way to achieve this using selenium or any other automation tool.
Greetings.
yes indeed you can by using chrome driver and selenium
code:
driver= webdriver.Chrome(executable_path="ChromeDriverExeLocation")
driver1= webdriver.Chrome(executable_path="ChromeDriverExeLocation")
driver.get("googleloginform")
driver1.get("googleloginform2")
How to change profile preference after defining driver?
profile = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_profile=profile)
After some code need to set useragent
profile.set_preference("general.useragent.override", ua)
How to set it without defining new driver?
As per the current implementation of Selenium once you configure the GeckoDriver with specific Capabilities and initialize the firefox session to open a Browsing Context, you cannot change the capabilities runtime. Even if you are able to retrieve the runtime capabilities still you won't be able to change them back.
So, in-order to change the Firefox User Preference you have to initiate a new WebDriver session.
Note:However, you can change the user-agent for Firefox on each run and you can find a relevant discussion in How to change user agent for Firefox webdriver in Python?
Reference
Here is #JimEvans clear and concise comment (as of Oct 24 '13 at 13:02) related to proxy settings capability:
When you set a proxy for any given driver, it is set only at the time WebDriver session is created; it cannot be changed at runtime. Even if you get the capabilities of the created session, you won't be able to change it. So the answer is, no, you must start a new session if you want to use different proxy settings.
Outro
You can find a couple of relevant detailed discussions in:
Python and selenium: how to change Firefox's profile multiple times
I believe it’s not possible but I found some workarounds explained in this article, not sure if those approaches are reliable though (or work at all): https://tarunlalwani.com/post/change-profile-settings-at-runtime-firefox-selenium/
I need to allow flash content in an automated manner in Python. I tried using Selenium in Python to do so but could not manage. The issue is that browsers stopped supporting settings that always allow flash content. Moreover, the "Allow" button cannot be accessed via Selenium for instance because it is not a part of the website or a setting in Firefox. Does anyone know about a potential workaround?
Here is an image of the Firefox message that I need to somehow access:
"...The Allow button cannot be accessed via Selenium for instance because it is not a part of the website or a setting in Firefox. Does anyone know about a potential workaround?"
I don't know your OS but if it was my problem...
Try to find a "key press" module to send the A key press into Firefox (ie: the Allow shortcut).
Try to send a mouse-click at the coordinates of Allow button.
A good option to try is pyautogui. Once Flash is enabled by such module (clicker or presser) then you can involve Selenium for whatever you needed to do in the enabled Flash.
To allow flash content in an automated manner using Selenium through Python you need to use an instance of FirefoxProfile() and set_preference() method to configure:
dom.ipc.plugins.enabled.libflashplayer.so to true
plugin.state.flash to 2
Code Block:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("dom.ipc.plugins.enabled.libflashplayer.so","true")
profile.set_preference("plugin.state.flash", 2)
driver = webdriver.Firefox(firefox_profile=profile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
I am running some code with selenium using python, and I figured out that I need to dynamically change the UserAgent after I already created the webdriver. Any advice if it is possible and how this could be done? Just to highlight - I want to change it on the fly, after almost each GET or POST request I send
I would go with creating a new driver and copy all the necessary attributes from the old driver except the user agent.
I am using Selenium in Python to automate a remote browser. The browser needs access to its webcam and microphone. When I navigate to a page that requests access, Firefox shows a pop-up window that asks "Would you like to share you camera and microphone with [host]?"
This window is not part of the browser's page, so it cannot be detected or controlled via Selenium.
This behavior is controlled by the media.navigator.permission.disabled option in Firefox's 'about:config' page. If this option is set to 'true', then access to the camera should be granted automatically.
When I set that option to 'true', it eliminates the prompt only when I run Firefox manually. When I run Firefox via Selenium, I still get the prompt.
How can I suppress this prompt, and have permission granted automatically?
The problem lies in Firefox profiles. Selenium creates a new, temporary profile for each browser instance. This profile is separate from the profile you use when you manually start Firefox.
Thus, when you set media.navigator.permission.disabled to 'true' in about:config, you do so only for your profile, and not for the profile that Selenium uses.
There are two ways to work around this:
Tell Selenium which existing profile to use.
To do this, you must first determine which profile you are using. To do this, close all instances of Firefox, then execute firefox -p to start the profile manager. In most cases, you will see a single profile called default.
Using this profile, navigate to about:config, and set the media.navigator.permission.disabled option to true.
Then, when you start the Selenium standalone server, specify this profile:
java -jar selenium-server-standalone-2.37.0.jar -Dwebdriver.firefox.profile=default
This tells Selenium to use the default profile, which has the settings you want.
Create and configure a new profile for Selenium to use.
Before you create the browser instance, you must create a Firefox profile and configure it to meet your needs:
profile = webdriver.FirefoxProfile()
profile.set_preference ('media.navigator.permission.disabled', True)
profile.update_preferences()
Then specify this profile when you create the remote browser instance:
firefox = selenium.webdriver.remote.webdriver.WebDriver (command_executor=my_url, desired_capabilities=DesiredCapabilities.FIREFOX, browser_profile=profile)
Selenium will then use this profile, and you should not be prompted for permission to access the camera.
Note that this method takes more time than the first method.
You can use options:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.set_preference("media.navigator.permission.disabled", True)
browser = webdriver.Firefox(options=options)