0

I hope you are all well =) this is my first post/question on stackoverflow =)

I'm writing this after trying all the answers in this thread. (the last answer I tried was from Youssof H.)

I'm a python newbie and trying to write a script that can help me upload products to a website. Since I need to be logged in to be able to add products, I figured why not use a browser profile where I'm already logged in, instead of writing code to get this done (I figured using a browser profile would be easier)

I've been trying to get this working for many hours now and I don't seem to be able to solve this by myself.

When I run the code, instead of opening Chromium it keeps opening google-chrome. Prior to trying to use chromium I tried it with chrome, if I open chrome it opens google-chrome-stable but when I run the python file it runs google-chrome.

My operating system is Mint 20.1 (Cinnamon) and I use Visual Studio Code

If anyone can help me with this it would be highly appreciated =)

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# Do not use this path that is extracted from "chrome://version/"
exec_path_chrome = "/usr/bin/chromium"
exec_path_driver = "/home/equinix/drivers/chromedriver"

ch_options = Options()  # Chrome Options
# Extract this path from "chrome://version/"
ch_options.add_argument(
    "user-data-dir = /home/equinix/.config/chromium/Default")

# Chrome_Options is deprecated. So we use options instead.
driver = webdriver.Chrome(executable_path=exec_path_driver, options=ch_options)

driver.get("https://duckduckgo.com/")

2 Answers2

0

I dont have the same paths but, you can pinpoint the exact binary that you want to use, either chromium or chrome

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# Do not use this path that is extracted from "chrome://version/"
exec_path_chrome = "/usr/lib/bin/chromium"
exec_path_driver = "/home/art/drivers/chromedriver"

ch_options = Options()  # Chrome Options
# Extract this path from "chrome://version/"
ch_options.add_argument(
    "user-data-dir = /home/art/.config/chromium/Default")

# in your case its "/usr/lib/bin/chromium/chromium"
ch_options.binary_location = '/usr/lib/chromium/chromium'

#to point to google-chrome-stable
#ch_options.binary_location = '/opt/google/chrome/google-chrome'

# Chrome_Options is deprecated. So we use options instead.
driver = webdriver.Chrome(executable_path=exec_path_driver, options=ch_options)

driver.get("https://duckduckgo.com/")
art_architect
  • 919
  • 6
  • 8
  • Thanks @art_architect. Managed to get it to open Chromium but it still doesn't retrieve the correct profile. This is what i get when I go to chrome://version/ Executable Path /usr/lib/chromium/chromium Profile Path /tmp/.com.google.Chrome.YM3zZE/Default – Equinix May 18 '21 at 07:13
  • Command Line.... /usr/lib/chromium/chromium --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.YM3zZE --user-data-dir = ./home/equinix/.config/chromium/Default --flag-switches-begin --flag-switches-end data:, – Equinix May 18 '21 at 07:18
  • I'm out of ideas on why the profile is pointing tot hat location. Did you install the chromium via sudo apt-get install chromium ? or an archive extraction ? – art_architect May 18 '21 at 14:08
  • Thanks for taking your time @art_architect to have a look at this. I installed it via sudo apt install chromium .... When starting this "project" I never envisioned being stuck so long at the beginning of this script. Lol – Equinix May 18 '21 at 16:01
  • When I add *** ch_options.add_argument("profile-directory=Monkey") *** I get *** Profile Path /tmp/.com.google.Chrome.6xxT6e/Monkey *** in the Profile Path (in chrome://version . So it seems to be reading that argument but not the one directing it to user-data-dir – Equinix May 18 '21 at 16:20
  • Hmm can you try with ch_options.add_argument("user-data-dir = /home/equinix/.config/chromium") without the default. – art_architect May 18 '21 at 19:24
  • I've already tried that when I went through the other thread (https://stackoverflow.com/a/31063104/15953884) Unfortunately non of the suggested ways to resolve this worked. Did manage to auto-login to the page I need to upload products to, but a bit bumped out as I don't like failure. lol =/ – Equinix May 18 '21 at 19:47
0

I use such a simple construction, but it only works when you have one google chrome profile.

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time
from selenium.webdriver.common.by import By

chrome_options = Options()
chrome_options.add_argument("user-data-dir=C:/Users/yourusername/AppData/Local/Google/Chrome/User Data/") 
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get("https://google.com/")
NOLOUNAME
  • 1
  • 2