Here's one way to select/click the checkbox with a complete solution.
this is the website , for example.
and let's say this is the desired checkbox on the given website (marked under red loop) to perform a click.

solution:
import time
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import selenium.webdriver.support.expected_conditions as EC
driver = Chrome()
driver.get('https://register.whirlpool.com/en-us/registration')
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'privacy_policy')))
driver.execute_script("document.getElementById('privacy_policy').click();")
time.sleep(2)
var1 = driver.find_element(By.ID, "privacy_policy").is_selected()
print(var1)
output:
True
- First, we wait and locate the element By the available methods(here
By.ID) to make sure that the target checkbox element is loaded/located on the page.
- Next, execute the javascript query (here
document.getElementById('privacy_policy').click()) to click on the checkbox.
- We can also verify if the click or the select was performed on the desired
checkbox using the method is_selected() as mentioned above.
- It'll return
True if the checkbox was clicked/selected and False otherwise.
You can also cross-check by simply running the javascript query document.getElementById('privacy_policy').click() on the Console of the page and you'll see that it indeed performs the click on the desired checkbox.
