Selenium does not use my custom profile in Chrome - python

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.

Related

How to use normal chrome completely without chromedriver selenium python not duplicate

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.

Selenium - Cant interact with web driver

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')

Extensions not loading in Chrome driver Profiles Selenium

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/

Selenium server throws error when attempting to run test with chrome or Internet Explorer

I have a python webdriver script which successfully runs the test on the remote server using firefox, however it throws an error when using chrome and internet explorer.
I have added the directory with both drivers to the server's path. I have also tried starting the server using:
java -jar .\selenium-server-standalone-2.45.0.jar -Dwebdriver.ie.driver=.\IEDriverServer.exe -role hub
I consistently get the same error in powershell:
"... - Exception: The path to the driver executable must be set by the webdriver.chrome.driver system property;..."
Working Script:
def setUp(self):
self.wd = webdriver.Remote(
desired_capabilities=DesiredCapabilities.FIREFOX)
Throws Error:
def setUp(self):
self.wd = webdriver.Remote(
desired_capabilities=DesiredCapabilities.CHROME)
What is the culprit of this problem?
You have the Selenium driver for Firefox installed and configured, but not for Chrome. Installing and configuring boils down to this (source):
Setup
ChromeDriver is a separate executable that WebDriver uses to control
Chrome. It is maintained by the Chromium team with help from WebDriver
contributors. If you are unfamiliar with WebDriver, you should check
out their own Getting Started page.
Follow these steps to setup your tests for running with ChromeDriver:
Ensure Chromium/Google Chrome is installed in a recognized location
ChromeDriver expects you to have Chrome installed in the default
location for your platform. You can also force ChromeDriver to use a
custom location by setting a special capability.
Download the ChromeDriver binary for your platform under the downloads section of this site
Help WebDriver find the downloaded ChromeDriver executable
Any of these steps should do the trick:
include the ChromeDriver location in your PATH environment variable
(Java only) specify its location via the webdriver.chrome.driver system property (see sample below)
(Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)
So, basically, you need to either set the path to your Chrome drive in the PATH, or instantiate the drive like this:
driver = webdriver.Chrome('/path/to/chromedriver')
Download the Chromedriver
from selenium import webdriver
driver = webdriver.Chrome('C:\\Users\\xxx\\Downloads\\chromedriver_win32\\chromedriver.exe')
driver.get("http://www.seleniumhq.org/")
The code is for JAVA , set the path similarly in python
If the PATH is not set in your environment variable , then set it programmatically as below:
System.setProperty("webdriver.chrome.driver", "Path_to_your_chromedriver.exe");
driver = new ChromeDriver();

Does Chrome Web Drivers needs to be in Client's System while using Selenium

I have tried searching the official documentation, but no result. Does Chrome Web Driver needs to be in client's system for a python script using Selenium to run? I basically want to distribute compiled or executable file versions of the application to the end user. How do i include Chrome Web driver with that package?
Yes you will have to download and put chromedriver to your system and then need to call in selenium code.
Download chromedriver from here : Chromedriver for selenium
Below code will help you to call chrome driver using selenium with python :
import os
from selenium import webdriver
chromedriver = "/Users/mike/Downloads/chromedriver" [you please put your actual path of chrome driver]
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
Hope this help you.
If you are using selenium RC , then you can set path like below :
selenium = new DefaultSelenium(Server, ServerPort, "*googlechrome", DomainURL);
chromedriver needs to be installed on the machine that will launch the instance of the Chrome browser.
If the machine that launches the Chrome instance is the same machine as where the Python script resides, then the answer to your question is "yes".
If the machine that launches the Chrome instance is a machine different from the machine that runs your Python script, then the answer to your question is "no".

Categories