[Python] Chrome profile is selected but not loading the website with Selenium

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    I’m using Selenium with Python to open a Chrome browser using my existing user profile. The browser opens, and the correct profile is selected, but when I try to navigate to a website (like YouTube), it just keeps loading and never finishes.

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

    # Path to your ChromeDriver
    chrome_driver_path = r"C:\Users\msi\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe"

    # Path to your Chrome user profile
    user_profile_path = r"C:\Users\msi\AppData\Local\Google\Chrome\User Data"
    profile_directory = "Profile 6"

    # Setup Chrome options
    chrome_options = Options()
    chrome_options.add_argument(f"user-data-dir={user_profile_path}")
    chrome_options.add_argument(f"profile-directory={profile_directory}")

    # Disable the "Chrome is being controlled by automated test software" infobar
    chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
    chrome_options.add_experimental_option("useAutomationExtension", False)

    # Start Chrome driver
    service = Service(executable_path=chrome_driver_path)
    driver = webdriver.Chrome(service=service, options=chrome_options)

    # Open YouTube
    driver.get("https://www.youtube.com")

    Continue reading...

Compartilhe esta Página