So, I want to use my existed profile on chrome to make easily to login and fetch some data from the website. So I tried this on my current codes but it doesn't load the profile for some reason,
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import time
class ClientDriver:
def __init__(self):
self.options = Options()
self.options.add_argument("--lang=en_US")
self.options.add_argument("--disable-gpu")
self.options.add_argument("--no-sandbox")
self.options.add_argument("--disable-dev-shm-usage")
self.options.add_argument(
r"user-data-dir=C:\Users\User\AppData\Local\Google\Chrome\User Data\Profile 1"
)
self.options.add_argument("--profile-directory=Profile 1")
def check(self):
driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()), options=self.options
)
driver.get("chrome://version/")
time.sleep(100)
x = ClientDriver()
x.check()
As can you see on my current codes, it will redirect to chrome://version/
to check the Profile Path and it's not C:\Users\User\AppData\Local\Google\Chrome\User Data\Profile 1
but it was C:\Users\Users\AppData\Local\Google\Chrome\User Data\Profile 1\Profile 1
. Can someone help me out?
CodePudding user response:
You're checking chrome://version/
from your selenium test, of course you see a wrong path!
You should instead open a normal chrome window, insert chrome://version/
in the search bar, press enter and check from there your profile path.
You will see it will be something like C:\Users\User\AppData\Local\Google\Chrome\User Data\Profile 1
And so in the code you'll have to write:
self.options.add_argument(
r"user-data-dir=C:\Users\User\AppData\Local\Google\Chrome\User Data"
)
self.options.add_argument("--profile-directory=Profile 1")