Search code examples
pythonpython-3.xselenium-webdriverselenium-chromedriver

Selenium Python login using Chrome profile


I am trying to use a Chrome profile to login to skinport.com.

Here is my code:

"""

option = uc.ChromeOptions()

option.add_argument(
     rf'--user-data-dir=C:\Users\kumpd\AppData\Local\Google\Chrome\User Data')
option.add_argument(r'--profile-directory=Default')
option.add_argument("--log-level=3")
driver = uc.Chrome(options=option)

time.sleep(2)

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

time.sleep(3)

"""

The program successfully opens a Chrome browser where I am logged into Google, but then I get this error:

"""

Traceback (most recent call last):
  File "C:\Users\kumpd\OneDrive\Desktop\BuffMarket Purchase Bot V3.0\Testing.py", line 18, in <module>
    driver = uc.Chrome(options=option)
             ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\undetected_chromedriver\__init__.py", line 53, in __new__
    instance.__init__(*args, **kwargs)
  File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 93, in __init__
    RemoteWebDriver.__init__(
  File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 357, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 418, in execute
    self.error_handler.check_response(response)
  File "C:\Users\kumpd\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
    GetHandleVerifier [0x0087DCE3+50899]
    (No symbol) [0x0080E111]
    (No symbol) [0x00715588]
    (No symbol) [0x0073281C]
    (No symbol) [0x0072F479]
    (No symbol) [0x00761FFE]
    (No symbol) [0x00761CEC]
    (No symbol) [0x0075B6F6]
    (No symbol) [0x00737708]
    (No symbol) [0x0073886D]
    GetHandleVerifier [0x00AE3EAE+2566302]
    GetHandleVerifier [0x00B192B1+2784417]
    GetHandleVerifier [0x00B1327C+2759788]
    GetHandleVerifier [0x00915740+672048]
    (No symbol) [0x00818872]
    (No symbol) [0x008141C8]
    (No symbol) [0x008142AB]
    (No symbol) [0x008071B7]
    BaseThreadInitThunk [0x76D97D49+25]
    RtlInitializeExceptionChain [0x77B6B74B+107]
    RtlClearBits [0x77B6B6CF+191]

"""

Any idea what could be causing this error? Also, for reference, I navigated to a webpage where my Chrome priofile should have me logged in, but I am not logged in.

Thanks for any help

*UPDATE

I am still getting the same error, but with the following code I can manually navigate to the webpage and I am logged in:

exec_path_driver = r"C:\chromedriver_win32\chromedriver.exe"

ch_options = Options()
ch_options.add_argument("user-data-dir=C:\\Users\\kumpd\\\AppData\\Local\\Google\\Chrome\\User Data")

driver = webdriver.Chrome(executable_path=exec_path_driver, options=ch_options)

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

My problem now is that the error prevents anything following in the program to be prevented from running, so I still very much need to fix it.


Solution

  • I was able to get it to work with this code:

    ch_options = Options()
    ch_options.add_experimental_option("detach", True)
    ch_options.add_argument("user-data-dir=C:\\Users\\kumpd\\\AppData\\Local\\Google\\Chrome\\User Data")
    
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=ch_options)
    
    time.sleep(2)
    
    driver.get("https://skinport.com/market?cat=Container&item=Glove+Case&sort=price&order=asc")
    

    I believe the problem was the exec_driver_path I was using. I was also missing the Service object.