I'm trying to set up any ad blocker to work with Firefox Selenium. I've set up a new profile and downloaded 3 most popular ad blockers, however when launching with Selenium none of them even show up in the Firefox extensions page. If I open Firefox normally, or if I go to about:profiles and click on the [Launch Profile in new Browser] then it shows up.
This is the python code:
# Get the path
profile_path = r'C:\Users\Sajev\AppData\Roaming\Mozilla\Firefox\Profiles\dyydkved.PythonScraper'
# Set up the webdriver options
options = Options()
options.set_preference('profile', profile_path)
# Create a webdriver object
driver = webdriver.Firefox(options=options)
driver.get(url2)
I've looked online and found this Github thread: https://github.com/mozilla/geckodriver/issues/1517
And I've tried the workaround mentioned there to lower the LastAppBuildID by 1 both by changing the number in prefs.js and in the python code like this:
options.SetPreference("extensions.lastAppBuildId", "<apppID> -1 ");
But it still doesn't work.
I also tried to make selenium install an extension on launch but fun times, that method is deprecated....
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 use Selenium (3.141.0) with ChromeDriver (87.0.4280) to access a page. When accessed manually, it brings me to a policy page (different URL) where you have to hit 'Ok' before continuing to the site. Edit This is using Win 10 and I have the folder with the chromedriver on PATH.
When using the following code, I'm able to get to the policy page with the ("--headless") option but without it I get a blank page with 'data:,' in the URL and nothing else loads. I've tried accessing straight from the policy page and the site URL but they both get stuck when the webdriver is created. Am I missing something? I'm open to any suggestions, thanks!
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
driver_path = 'D:\....\chromedriver.exe'
driver = webdriver.Chrome(executable_path= driver_path, options= chrome_options)
driver.get(...) # left out the url
This is the output page I get without using ("--headless")
Funny enough, I realized it was because my Chrome Developer tools had become disabled. Not sure how but when I re-enabled them, it worked perfectly again. Weird.
I am trying to load a profile to selenium so that I don't have to keep log in to the website that selenium is about to visit. I am running it with Python on my Mac.
In the Firefox version, I use the below code:
def create_selenium_FF():
profile = webdriver.FirefoxProfile('/Users/Victor/Library/Application Support/Firefox/Profiles/z3ay0enb.default')
driver = webdriver.Firefox(profile)
return driver
It can successfully start Firefox, but it doesn't have the log in info of the website that it visits, however I check in the automated Firefox browser using about:profiles, it does recognise the profile that I feed it.
In the Chrome version, I use the below code, notice I make a local copy of the profile already.
def create_selenium_chrome():
DRIVER = 'chromedriver'
options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=/Users/Victor/Library/Application Support/Google/Chrome2")
options.add_argument("--profile-directory=Default")
driver = webdriver.Chrome(DRIVER, options=options)
return driver
It can also start Chrome, and looks like it has my profile, but it raises an error:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir
How can I get it working please?
I just solved the problem !
So here is my code :
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\%username%\\AppData\\Local\\Google\\Chrome\\User Data 2")
driver = webdriver.Chrome(executable_path=path,options=options)
driver.get("https://www.google.com")
The thing is, you'll get this error if there already is chrome opened on your computer !
So, i just copy / paste the folder User Data and rename the pasted one into User Data 2 so my chrome works with user data and selenium with user data 2 I guess.
I know that you've been waiting for a long time and I don't know if u still need this but here you got !!
Browser opens and driver loses its control. It starts the browser but it can't initiate the driver in order to use it and send_keys, or do anything.
The code runs using Ghost Browser, which is a chromium based browser.
What should be done in order to selenium get control over browser?
Ive tried to get session_id in order to attach selenium to existing browser but it didnt worked also, since it cant get the session_id, because selenium exits.
Code:
exe_path = r'C:\Users\Anonymous\AppData\Local\GhostBrowser\Application\ghost.exe'
driver = webdriver.Chrome(executable_path=exe_path)
driver = webdriver.Chrome(executable_path=exe_path)
Are you sure you use chrome? Maybe change the webdriver.Chrome
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)