This script opens a simple page with one checkbox. It prints if the checkbox is selected before and after clicking it twice.
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 driver (adjust path as needed)
options = Options()
options.add_argument('--headless') # Run without opening browser window
service = Service()
driver = webdriver.Chrome(service=service, options=options)
try:
# Open a simple page with a checkbox
driver.get('data:text/html,<html><body><form><input type="checkbox" id="agree" name="agree">I agree</form></body></html>')
checkbox = driver.find_element(By.ID, 'agree')
# Initially checkbox should not be selected
print(f'Initially selected: {checkbox.is_selected()}')
# Click checkbox to select it
checkbox.click()
print(f'After click selected: {checkbox.is_selected()}')
# Click again to deselect
checkbox.click()
print(f'After second click selected: {checkbox.is_selected()}')
finally:
driver.quit()