[Python] How to fix WebDriver.__init__( ) got an unexpected argument 'executable_path' error...

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

  1. Stack

    Stack Membro Participativo

    Here is the screenshot of the error

    A little backstory: I'm still new in all this coding/programming stuff. I'm now trying to learn how to automate something using python. So I tried automating account creating for Instagram (without any ill intentions ofcourse), and now I've come to this point where I am confused.

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.common.exceptions import TimeoutException
    import random
    import string
    import time

    def generate_random_email():
    return ''.join(random.choices(string.ascii_lowercase, k=10)) + '@example.com'

    def generate_random_username():
    return 'user_' + ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))

    def generate_random_password():
    return ''.join(random.choices(string.ascii_letters + string.digits + '!@#$%^&*', k=12))

    def generate_birth_date():
    year = random.randint(1980, 2000)
    month = random.randint(1, 12)
    day = random.randint(1, 28)
    return (year, month, day)

    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument("--disable-notifications")
    chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")

    driver = webdriver.Chrome(executable_path='chromedriver', options=chrome_options)
    wait = WebDriverWait(driver, 15)

    driver.get('https://www.instagram.com/accounts/emailsignup/')

    try:
    cookie_button = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Allow essential and optional cookies']")))
    cookie_button.click()
    except TimeoutException:
    print("Cookie acceptance button not found. Proceeding without it.")

    email = generate_random_email()
    email_field = wait.until(EC.presence_of_element_located((By.NAME, 'emailOrPhone')))
    email_field.send_keys(email)

    full_name = ' '.join(random.choices(string.ascii_letters.split(), k=2)).title()
    name_field = driver.find_element(By.NAME, 'fullName')
    name_field.send_keys(full_name)

    username = generate_random_username()
    username_field = driver.find_element(By.NAME, 'username')
    username_field.send_keys(username)

    password = generate_random_password()
    password_field = driver.find_element(By.NAME, 'password')
    password_field.send_keys(password)

    year, month, day = generate_birth_date()
    birthday_fields = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//select[@title='Year:'] | //select[@title='Month:'] | //select[@title='Day:']")))
    birthday_fields.send_keys(str(year)) # Year
    birthday_fields.send_keys(str(month)) # Month (numeric)
    birthday_fields.send_keys(str(day)) # Day

    time.sleep(2)

    submit_button = driver.find_element(By.XPATH, "//button[text()='Sign Up']")
    submit_button.click()

    try:
    error_element = wait.until(EC.visibility_of_element_located((By.ID, 'ssfErrorAlert')))
    print("Error during signup:", error_element.text)
    except TimeoutException:
    print("Form submitted. Check for verification steps (if any).")

    input("Press Enter to close the browser...")
    driver.quit()


    Here's the code

    Continue reading...

Compartilhe esta Página