install_addon is a method on the Firefox webdriver, but I'm running tests remotely. How can I install an add-on to a driver like the following:
driver = webdriver.Remote(
command_executor=SELENIUM_URL,
desired_capabilities=webdriver.DesiredCapabilities.FIREFOX
)
? It looks like creating a webdriver.FirefoxProfile() and using add_extension() should work, but it's currently broken.
The use case is testing the effect of Firefox add-on manifest.json's all_frames property.
Аfter a long search and visits on this topic from google i found solution
Install addon in you Firefox profile from browser, save it and set him into webdriver options.
Firefox profile creating
Open you firefox browser
Go to about:profiles
Create a New Profile
Launch browser with created profile
Install addons what you need
Export profile
Open root directory of your firefox profile (see in in about:profiles in Root Directory section)
Copy folder into you project
Python
from selenium.webdriver import FirefoxOptions, FirefoxProfile, Remote
# init options object
options = FirefoxOptions()
# init profile object with path to you profile
profile = FirefoxProfile('{path_to_your_profile_folder}')
# set profile into options
options.profile = profile
# init you Remote browser with created options (commented arguments for example)
driver = Remote(
options=options,
# command_executor= ...,
# desired_capabilities=...
)
It`s works for me. The disadvantage of this solution is the presence of a folder with a profile that needs to be stored somewhere
Related
I am stucking with a script to do the following
I want to open my local chrome in which I have several accounts logged in, so for this I do:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:/Program Files (x86)/Google/Chrome/Application/chrome.exe")
but when I do that
driver.get(url)
doesn't send me to the URL I want.
On the other hand if I do it with
driver = webdriver.Chrome()
driver.get(URL)
Everything goes smoothly but it opens it with the chromedriver.exe and therefore the accounts are not logged in.
Any idea how to open the local chrome and then be able to browse?
Any solutions for the problem
You need to load your user profile while initializing selenium webdriver.
You can do it using
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Path to local user profile") #Path to your chrome profile
w = webdriver.Chrome(executable_path="C:\\Path to your local chrome.exe installation", chrome_options=options)
Typing chrome://version/ in chrome address bar will show you the path to user profile.
In automation, when we use Selenium to interact with a web browser, we need a browser driver to communicate with the specific browser. ChromeDriver is the specific driver for Google Chrome. When you use webdriver.Chrome(), it launches the Chrome browser using the ChromeDriver executable. Chromedriver is a bridge between your Selenium script and the Chrome browser exactly as taxi driver is a bridge between you and taxi car.
Chrome uses profiles. By default in tests are not used local profiles of users. The new temporary profile is created instead. However, it is possible to point out the profile which should be used.
You need to pass additional argument user-data-dir to the Chrome options when initialising the Chrome driver, in order to open the local default Chrome profile. If you need to point out specific profile then you should use profile-directory.
Example:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument(r"--user-data-dir=C:/Users/[username]/AppData/Local/Google/Chrome/User Data")
options.add_argument(r'--profile-directory=YourProfileDir')
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get(URL)
To find the profile folder on Windows right-click the desktop shortcut of the Chrome profile you want to use and go to properties -> shortcut and you will find it in the "target" text box.
See also the following answers:
https://stackoverflow.com/a/66179265/21085370
https://stackoverflow.com/a/69251146/21085370
https://stackoverflow.com/a/67389309/21085370
The official documentation is here
I'm trying to automate some tasks with Selenium and I need to interact with certain extensions, so I created a profile that would keep this extensions.
Since Chrome's new update, my script stopped working because it wasn't opening the right profile anymore.
My code:
def open_browser():
optionsinput = webdriver.ChromeOptions()
optionsinput.add_argument("user-data-dir=/Users/User1/Library/Application\ Support/Google/Chrome/Profile 13")
# Open the browser
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options = optionsinput)
driver.implicitly_wait(10) # seconds
return driver
When I try to open the extension, I find that the extension is not installed in the profile and I get this:
and further investigation by opening chrome://version/ shows that it's adding /Default to the user path:
Profile Path /Users/User1/Library/Application\ Support/Google/Chrome/Profile 13/Default
I'm out of ideas on how to fix it... I've created new profiles, tried to create a default folder within the profile that would hold the extension... nothing.
I am working with python and selenium to set up a webscraper. I used the ChromeOptions module to open the chrome browser with a specific chrome user I have created. User name is: run_scraper_run. After creating the user a desktop connection has been created. I checked the desktop connection for the profile directory and copied the respective directory path. When I run the script it opens a browser but it seems like it opens another instance of google chrome. There is neither my default account selectable nor the one I created for the scraper. It seems like a separate environment if I can say that in that case. Does anyone have an idea what could have gone wrong or how I can get the created user account to be used?
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
options = webdriver.ChromeOptions()
options.add_argument(r'--user-data-dir=C:\Users\test\AppData\Local\Google\Chrome\User Data\run_scraper_run')
options.add_argument('----profile-directory="run_scraper_run"')
ser = Service(r'C:\[PATH OF CHROMEDRIVER]')
driver = webdriver.Chrome(options = options, service = ser)
This is my actual environment:
But this opens instead despite the same path as in the desktop icon properties
I believe you have the wrong user data directory path.
The user data directory path that you provide is actually the Profile path.
The following change should fix the issue:
options.add_argument(r'--user-data-dir=C:\Users\test\AppData\Local\Google\Chrome\User Data')
options.add_argument('----profile-directory="run_scraper_run"')
P.S. Verify that the Profile Directory name is correct. You can do this by checking that by accessing chrome://version in the chrome browser having the desired profile.
Why am I doing this:
I need to automate a website that requires client-side SSL certificates. I understand this to be an option which cannot be specified using fp.set_preference(). I am not in control of the server I am connecting to thus I cannot change the security setup.
What have I tried
I have created a separate Firefox profile which has the required 'client-side password protected SSL certificates' set up, select one certificate automaticaly and some manual proxy settings (SOCKS 5). After much googling I have set my code as follows:
from selenium import webdriver
url = 'https://www.paininneck.co.uk'
fp = webdriver.FirefoxProfile(r"""C:\Users\
<user>\AppData\Local\Mozilla\Firefox\Profiles\<Firefox>""")
driver = webdriver.Firefox(fp)
driver.get(url)
The Problem:
The browser does open, however, it is still using the default profile. None of the settings I have changed in the other profile has copied across. The profile specified in my code is still working with selecting it through the Firefox UI.
I am hoping I missed something simple and all this time googling has not been in vain! I am reluctant to change to default settings, however after tweaking the default profile to see if the settings would copy over it is apparent that they don't and Selenium is making a clean copy each time.
Kind regards
Rich
Versions:
Python==3.6.1,
Selenium==3.4.3,
Firefox==53
gecko driver==v0.16.1
OS==Windows(Its for work dont judge me!)
Using Selenium 3.4.x, Python 3.6.1 along with geckodriver v0.16.1 & Mozilla Firefox 53.0, you can use the existing Firefox profile through the following steps:
Locate the Firefox Profile directory on your windows box. For e.g. my Firefox Profile "debanjan" was located at C:\\Users\\AtechM_03\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles by the name w8iy627a.debanjan.
Next, you have to specify the absolute path of the Firefox Profile directory when you initiate the webdriver.
Here is the working code which opens an existing Firefox Profile 'debanjan' on my Windows machine:
It is to be noted that the current Selenium-Python binding is unstable with geckodriver and looks to be Architecture specific. You can find the github discussion and merge here. So you may additionally need to pass the absolute path of the firefox binary while initializing the webdriver
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
profile = webdriver.FirefoxProfile('C:\\Users\\AtechM_03\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\w8iy627a.debanjan')
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
url = 'https://www.paininneck.co.uk'
driver.get(url)
I need to put Firefox plugin path for Firefox profile which I am using.
profile = webdriver.FirefoxProfile(plugin_path)
profile.set_preference("webdriver.load.strategy", "fast")
How to find Firefox plugin path in Linux so that I can pass the plugin_path on my python script
I'm not sure why you want to load plugin this way to FirefoxProfile? Docs have a different example:
File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen
WebDriver driver = new FirefoxDriver(firefoxProfile);
Anyway, plugins for Firefox are located in ~/.mozilla/firefox/MY_PROFILE/extensions