[Python] Selenium webdriver isn't clicking on checkbox (Python)

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

  1. Stack

    Stack Membro Participativo

    I have tried using the full XPATH of the <input> and the <label> containing it, as well as the ID the input has. But when calling .click() on it, it will scroll to the desired item but will not click it. The relevant code is below with each variation mentioned above but only one is currently calling .click()

    is_raining_1 = driver.find_element(By.XPATH, '/html/body/div/div/div/main/div/div[1]/div/div[2]/div[1]/div/div[1]/label[1]/input')
    is_raining_2 = driver.find_element(By.XPATH, '/html/body/div/div/div/main/div/div[1]/div/div[2]/div[1]/div/div[1]/label[1]')
    is_raining_3 = driver.find_element(By.ID, 'isRaining')

    is_raining_1.click()


    (edited) The HTML for the element is:

    <label class="flex items-center select-none cursor-pointer space-x-2">
    <input id="isRaining" type="checkbox" class="form-checkbox h-5 w-5 text-blue-600">
    <div>
    <span class="text-sm">Raining</span>
    </div>
    </label>

    Continue reading...

Compartilhe esta Página