[Python] How to click checkbox using selenium and python

Discussão em 'Python' iniciado por Stack, Março 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to click on a checkbox using Selenium and Python. Here are the codes:

    HTML

    <div class="form-check">
    <input class="form-check-input" type="checkbox" value="" id="flexCheckChecked" required="">

    <label class="form-check-label" for="flexCheckChecked">
    Saya telah membaca dan setuju atas
    <a href="#" data-bs-toggle="modal" data-bs-target="#modal-snk"><span class="underline text-white">Syarat &amp; Ketentuan </span></a>,
    <a href="#" data-bs-toggle="modal" data-bs-target="#modal-privacy"><span class="underline text-white">Kebijakan Privasi </span></a>
    </label>
    </div>


    What I've tried:


    1. WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.form-check input#flexCheckChecked[class='form-check-input']"))).click() This gives a timeout error


    2. checkbox = driver.find_element(By.XPATH, '//*[@id="flexCheckChecked"]').click() This doesn't do anything


    3. ActionChains(driver).move_to_element(checkbox).click().perform() This also doesn't do anything


    4. checkbox = driver.find_element(By.ID, "flexCheckChecked") This gives an error "selenium.common.exceptions.ElementNotInteractableException: Message..."

    Please help

    Continue reading...

Compartilhe esta Página