selenium 3.6.0 and extensions - python

Note that I edited the question.
How to activate blocking for ghostery extension in firefox through selenium python bindings? Note that by default the blocking in ghostery is disabled.
I am using selenium 3.6.0 and ghostery 7.3.3.7. Note that I am using selenium + pull request #4790 that allow the new web extensions, because the released version lack this feature.
I do the following:
from selenium import webdriver
fp = webdriver.FirefoxProfile()
fp.add_extension(extension=/home/nsarafij/ghostery-7.3.3.7.xpi)
driver = webdriver.Firefox(firefox_profile = fp)
Is it possible to activate blocking in ghostery through setting preferences?
fp.set_preferances(...)
Or, I have to do something different?

I am not sure i understand you correctly - you want to add Ghostery to Firefox right?
If so, this should work:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
firefoxProfile = FirefoxProfile()
ghostery="PATH_TO_GHOSTERY_ADDON"
firefoxProfile.add_extension(ghostery)
firefoxProfile.update_preferences()
driver = webdriver.Firefox(firefoxProfile)

Related

no code runs after defining webdriver in selenium

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = Options()
options.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
print("hello world")
running python 3.10 on linux ubuntu
I was trying to play aruond with selenium however any code that I write after defining the webdriver does not work.
it seems that the interpreter gets stuck after defining the webdriver. it opens the webdriver but only shows "data:," and nothing else and won't respond to any code written after.
Chromium support is limited on selenium in my experience.
Please look at the replies here which do mention chromium-driver and how to get it
sudo apt-get install chromium-chromedriver
Should get you chromium driver and they have some example code there that doesn't look too outdated.
I figured out the problem, I only had chromium installed on my computer and I assumed that the chromium drivers and the chrome drivers are the same thing(still can't find any refrence to the chromium drivers)

How can I choose which firefox executable to use among multiple firefox binaries through Python selenium

I'm using python (v 3.65) selenium (v3.11.0) on Mac OS X (v 10.11.6) with firefox (v 59.0.3) and geckodriver (v 0.20.1). I have my usual firefox in the Applications folder and a second firefox in another folder. How can I tell python selenium to use the second firefox instead of going to the one in Applications?
I'd prefer an answer that generalises to other browsers besides firefox/geckodriver, if possible.
To choose and use one of the Firefox executable among multiple you can use the argument binary_location from firefox.options. As an example in the following code block I have used the Firefox Nightly binary to open the Firefox Nightly browser :
Code Block :
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'C:\Program Files\Firefox Nightly\firefox.exe'
driver = webdriver.Firefox(firefox_options=options, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get('http://google.com/')
print("Firefox Browser Invoked")
driver.quit()
Console Output :
Firefox Browser Invoked

How can I use selenium in Raspbian python3?

I'm using:
Raspberry Pi3
OS : Raspbian
language : python 3.5
Geckodriver : geckodriver-v0.19.1-arm7hf (usr/local/bin/geckodriver)
browser firefox esr (52.6.0 (32-bit))
Code:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.python.org')
Opening the browser is OK, but why did it fail to get URL?
I don't know how to solve it.
While you initialize the webdriver and the Web Browser pass the argument executable_path along with the absolute path of the GeckoDriver binary and invoke the proper url as follows :
from selenium import webdriver
driver = webdriver.Firefox(executable_path='usr/local/bin/geckodriver')
driver.get("your_url")

Python Selenium Firefox driver - Disable Images

Before I have used the code below, but it doesn't work anymore with firefox update.
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
firefoxProfile = FirefoxProfile()
firefoxProfile.set_preference('permissions.default.image', 2)
I also tried this one below, it seems good but is there a way to disable images without add-on or 3rd party tools?
from selenium import webdriver
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.add_extension(folder_xpi_file_saved_in + "\\quickjava-2.0.6-fx.xpi")
firefox_profile.set_preference("thatoneguydotnet.QuickJava.startupStatus.Images", 2) ## Turns images off
Have you tried updating your selenium after the Firefox update?
eg :
sudo -H pip install --upgrade selenium

Python Selenium browser with extensions

I can't seem to find any information on how to set python to open a browser (firefox) but a version that has an extension installed such as adblock?
Thanks.
Instantiate FirefoxProfile() and use add_extension() to add an existing extension:
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.add_extension('path_to_extension')
profile.set_preference("extensions.adblockplus.currentVersion", "2.4")
driver = webdriver.Firefox(firefox_profile=profile)

Categories

Resources