how to find firefox plugin path in Linux - python

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

Related

Adding extension through selenium firefox profile success. But when I open these Firefox manually, the extension still not installed

I use selenium python. My code work success, the extension was added. But when I close the code, open the Firefox Profile which added extension by manually then the extension isn't installed.
My code
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
try:
path = "My_profile_PATH"
fp = webdriver.FirefoxProfile(path)
driver = webdriver.Firefox(firefox_profile=fp)
# path to your downloaded Firefox addon extension XPI file
extension_path = "MY_extension_PATH"
# using webdriver's install_addon API to install the downloaded Firefox extension
driver.install_addon(extension_path, temporary=True)
# Opening the Firefox support page to verify that addon is installed
driver.get("about:support")
# xpath to the section on the support page that lists installed extension
addons = driver.find_element(By.XPATH,'//*[contains(text(),"Add-ons") and not(contains(text(),"with"))]')
# scrolling to the section on the support page that lists installed extension
driver.execute_script("arguments[0].scrollIntoView();", addons)
# introducing program halt time to view things, ideally remove this when performing test automation in the cloud using LambdaTest
print("Success. Yayy!!")
time.sleep(20)
except Exception as E:
print(E)
finally:
# exiting the fired Mozilla Firefox selenium webdriver instance
driver.quit()
# End Of Script
When you ask Selenium to use a profile, it copies it to a temporary location and use this copy. So whatever you do doesn't affect the original profile.
If you want your script to affect the original profile, don't ask Selenium to use a profile. Instead, tell Firefox directly which profile to use:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('-profile')
options.add_argument('/path/to/your/profile')
driver = webdriver.Firefox(options=options)

webbrowser user data dir opens different browser environment (python selenium )

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.

how to use chrome options in python after the browser opened [duplicate]

Scenario: There is a requirement of downloading files from web hierarchy to local drive under same hierarchy.
Example Web Hierarchy:
Parent 1:
Child 1:
*File 1
Child 2:
*File 2
When downloading File 1, it should store in path 1 - "C:\....\Downloads\Parent 1\Child 1\"
When downloading File 2, it should store in path 2 - "C:\....\Downloads\Parent 1\Child 2\"
Problem:
When I keep "C:....\Downloads\Parent 1\Child 1\" download path in chrome webdriver while initializing webdriver first time in setUp() & download "File 1", it downloads in expected folder.
But when I set next "C:....\Downloads\Parent 1\Child 2\" download path in chrome webdriver for downloading File 2 in it, it opens another chrome browser because I am using another webdriver for setting path 2.
Required Solution:
I want to use existing webdriver to set different chrome download paths or any other workaround you can think of.
Current Code:
def setUp(self):
browser = webdriver.Chrome(chromedriver_path, option_with_path_1_set)
def test_downloadFiles(self):
\*code to download first file\*
driver = webdriver.Chrome(chromedriver_path, option_with_path_2_set)
\*code to download second file\*
def tearDown(self):
browser.quit()
Please let me know if you require any additional information.
Thanks in advance!
When you configure an instance of a ChromeDriver through ChromeOptions to initiate a new Chrome Browser the configuration gets baked into the chromedriver executable which will persist for the lifetime of the WebDriver and remain uneditable.
Even if you are able to extract the ChromeDriver and ChromeSession attributes e.g. Session ID, Cookies and other session attributes from the initiated Browsing Session still you won't be able to change those attributes of the ChromeDriver.
A cleaner way would be to call driver.quit() within tearDown(){} method to close and destroy the ChromeDriver and Chrome Browser instances gracefully and then span a new set of ChromeDriver and Chrome Browser instance with the new set of configurations.
tl; dr
You can find a couple of relevant discussions in:
How to set selenium webdriver from headless mode to normal mode within the same session?
How do I make Chrome Headless after I login manually

How to install add-on on a remote Firefox webdriver?

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

Selenium - How to import all settings from an existing Firefox 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)

Categories

Resources