[Python] Selenium driver.get(url) does not open the URL

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

  1. Stack

    Stack Membro Participativo

    I tried to run a code that browses a URL by using Selenium Driver, but it doesn't work.

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

    # Setup Chrome options
    chrome_options = Options()
    chrome_options.add_argument("--headless=new") # Run in headless mode

    # Set path to chromedriver
    driver_path = "./chrome/chromedriver.exe"

    # Start the WebDriver
    service = Service(driver_path)
    driver = webdriver.Chrome(service=service, options=chrome_options)

    # Navigate to the page
    driver.get("https://example.com")

    # Optional: Wait for JavaScript to load
    time.sleep(3)

    # Find elements
    title = driver.find_element(By.TAG_NAME, "h1").text
    print(f"Page title: {title}")

    # Close the browser
    driver.quit()


    It doesn't give me any error; the browser shows up, but nothing else happens. I tried creating a new project and running the same code. What's the problem, and how should I fix it? Thanks.

    I tested the code with Python 3 in Windows 10.

    Continue reading...

Compartilhe esta Página