Advertisement
alphauser420

checkbox

Mar 12th, 2024
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By
  3. from selenium.webdriver.chrome.service import Service
  4. import time
  5. # Start the WebDriver (assuming Chrome in this example)
  6.  
  7.  
  8. driver_path = "C:\Apps\chromedriver\chromedriver-win64\chromedriver.exe"
  9. service = Service(driver_path)
  10.  
  11. # Start the WebDriver using the specified service
  12. driver = webdriver.Chrome(service=service)# Replace 'your_url' with the actual URL of the webpage
  13. driver.get('https://omayo.blogspot.com/')
  14. driver.maximize_window()
  15.  
  16. # Locate the checkbox element
  17. checkbox_element = driver.find_element(By.ID, 'checkbox2')
  18.  
  19. # Check if the checkbox is selected
  20. if not checkbox_element.is_selected():
  21. checkbox_element.click()
  22. print("Checkbox is selected")
  23. else:
  24. print("Checkbox is not selected")
  25.  
  26. # Close the WebDriver
  27. time.sleep(5)
  28. driver.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement