I am wanting to use Profiles in Selenium Chrome.
I have tried:
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\Bain3\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1") #Path to your chrome profile
w = webdriver.Chrome(chrome_options=options)
I do not believe the profile is being loaded correctly as the extensions are not being loaded with it and instead gives me normal chrome with chrome automation extension. I have done this in geckodriver with no issues.
My next question is, as I want to use profiles in Selenium chromedriver. How do I remove the profiles icon and images from Chrome as I often use Chrome by default. It seems pointless to have these icons when I already have names for the profiles in the shortcuts.
I tried:
start "" "c:\program files (x86)\google\chrome\application\chrome.exe" --new-window --disable-new-avatar-menu
as well as navigating through chrome://flags/
Any ideas on why extensions are not being loaded with profiles and if the profile button in chrome can be disabled as well as the icons?
Here's an image of the icons and profiles icon that I could not get to be disabled. https://ibb.co/hS4N45 .
i had the same issue then i used the extension crx file to add it on launch by using :
options.add_extension("idmgcext.crx")
the crx file is in the same folder as the script or provide full path if in another folder you can get chrome extension crx file using this site: https://chrome-extension-downloader.com/
Related
How to use normal chrome completely without chromedriver selenium python not duplicate.
I am using python 3.8.8,os is windows 7 ultimate with pycharm as
IDE and chrome version is around 96. and my problem is that whenever I use my python script to scrape a website it uses chromedriver and when I specify what's given below:
options = Options ()
options.add_argument(r"user-data-dir=my chrome path which is not Executable instead the user data")
#this works but when opening chrome it shows "browser is controlled by automated software" and changing it to normal chrome. Exe won't work
Sure it uses normal chrome with my credentials but it still needs chromedriver to work and when I delete the chromedriver it throw an error and when I go into selenium source code in a file called site.py(or sites.py) which I changed the variable self. executable to chrome.exe path and it worked and it won't show the message browser is controlled by automated software but it won't do anything , it is just stuck there and what I want to do is use chrome as the browser to scrape without chromedriver in my pc is it possible? If yes please tell me how should I go on to do it and you can ask for further Clarification and details and Thanks in advance
By default, selenium is detected as an automated software and is flagged by most websites, and the flag is unable to be removed. There are, however, external libraries that can be installed that can remove the flag.
There are options here to try to get around the default flag and hide the fact the browser is automated.
Edit
I understand the question further, and see that you want a more portable chrome option. Chrome driver is a very specific program controlled by selenium and must be used. There is no substitute. You can use Firefox driver or internet explorer, but a webdriver must be used (hence the name driver for driving the main browser). When you specify the directory for the Chrome binary, you aren’t removing the middleman of the chromedriver, only Specifying where chrome driver needs to look!
Using Selenium you won't be able to initiate/spawn a new Browsing Context i.e. Chrome Browser session without the ChromeDriver.
The Parts and Pieces
As a minimum requirement, the WebDriver i.e the ChromeDriver talks to a browser through a driver and the communication is two way:
WebDriver passes commands to the browser through the driver
Receives information back via the same route.
Hence using ChromeDriver is a mandatory requirement.
im trying to load a specific chrome profile using Python selenium webdriver, but i cant interact with the driver after assigning the chrome profile. it opens the chrome profile that i wanted, but from there - nothing. i cant do any action. for example - im trying to open Microsoft.com:
This works:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.microsoft.com')
But this doesnt work at all:
from selenium import webdriver
import getpass
username = getpass.getuser()
options = webdriver.ChromeOptions()
options.add_argument('user-data-dir=C:/Users/'+username+'/AppData/Local/Google/Chrome/User Data/')
driver = webdriver.Chrome(executable_path='C:/Users/'+username+'/Documents/selProject/chromedriver.exe', chrome_options=options)
driver.get('http://www.microsoft.com')
The above code opens chrome, but doesnt go to microsoft.com or any other action.
thanks for reading!
This is likely because you have Chrome open already with that user signed in.
In order to use chrome with that profile, while also running the script you'll need to separate the directories where the profiles are pulled from. That is, move (or copy) the Default profile to another directory that you call to within the user-data-dir argument.
You do following things and check whether it works.
Upgrade python bindings using
pip install -U selenium
for chrome browser download the latest chrome driver "ChromeDriver 2.45"
form http://chromedriver.chromium.org/downloads and write the code
from selenium import webdriver
driver=webdriver.Chrome("Path of the Chromedriver" + "chromedriver.exe" )
driver.get('http://www.microsoft.com')
I am using selenium with chrome, but it does not use the profile that I specified, but starts with a new profile instead. Here is the python code:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--user-data-dir=/home/username/.config/google-chrome/Profile 1')
driver = webdriver.Chrome(chrome_options=chrome_options)
The browser opens but it does not use my profile. The version of selenium is 3.5.0, the version of chrome driver is 2.31, the version of chrome is 60.0.3112.113, and I am on Ubuntu 16.04
To find path to your chrome profile data you need to type chrome://version/ into address bar . For ex. mine is displayed as
C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default,
to use it in the script I had to exclude
\Default\
so we end up with only
C:\Users\pc\AppData\Local\Google\Chrome\User Data.
Also if you want to have separate profile just for selenium: replace the path with any other path and if it doesn't exist on start up chrome will create new profile and directory for it.
Hope this helps. Thanks.
I have a web test tool developed with python using selenium 3 api. I run it in Firefox. There's a part in the website permits to download a tar.gz file. I want that the test tool download the file in a specified local folder without displaying popup download window.
So in init step and before opening the browser I added some preferences to the profile of Firefox like that:
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/x-gzip')
profile.set_preference("browser.download.folderList",2)
profile.set_preference("browser.helperApps.alwaysAsk.force", False)
profile.set_preference("browser.download.dir", downloadPath)
profile.set_preference("browser.download.manager.showWhenStarting", False)
But this code doesn't prevent displaying the download window and always ask me where to download the file.
In addition if check preferences of Firefox while test running I find that Downloads setting is save to Downloads folder not like what is set in browser.download.dir parameter.
Is there any idea to fixe this problem?
Development environment: Python 2.7, selenium 3.0.1, Firefox 49
Python v2.7 and Selenium I guess it is v2.49 (current last version)
I was able to add the extension (IETab V2):
profile=FirefoxProfile(profilePath)
profile.add_extension(extension=extensionPath)
driver = webdriver.Firefox(firefox_profile=profile)
Im normally able to configure the extension (when Im not using the browser through webdriver) and the configurations are there everytime I open the browser (Im setting the websites to be opened with IETab). However, when I open the browser through webdriver although the extension is there I lose the configurations.
Any idea how to keep the extensions configs when loading the browser through webdriver?
Thanks.
Most firefox extensions keep their settings in the profile settings. You can access those by typing about:config in your url bar. Find the corresponding settings and set them manually on your FirefoxProfile instance. If there's too many settings, search for prefs.js in your firefox profile directory. That's a snapshot of the settings in plain text from the last time you closed the browser.