mysocial
Connect with friends and the world around you on MySocial.
Create a Page for a celebrity, brand or business.
Online Learning Platform
Connect with friends and the world around you on MySocial.
Create a Page for a celebrity, brand or business.
Dummy ticket websites provide different web elements to do the automation
input[type="text"] { background-color : #e6ebff; }
Last Name
Date of birth*
Sex*
Male Female
| Select Option | City ID | City Name | Passengers |
|---|---|---|---|
| 6001 | Mumbai | 1033 | |
| 6002 | Pune | 2002 | |
| 6003 | Indore | 3000 | |
| 6004 | Kolkata | 5000 | |
| 6005 | Hyderabad | 6000 | |
| 6006 | Orangabad | 3456 | |
| 6007 | Delhi | 5666 |
The is_selected() method in Selenium is used to check whether a web element, such as a checkbox, radio button, or option in a dropdown, is currently selected or not. It returns True if the element is selected and False if it is not.
element.is_selected()
from selenium import webdriver
from selenium.webdriver.common.by import By
# Set up the driver (assuming you're using Chrome)
driver = webdriver.Chrome()
# Open a webpage with website example
driver.get('https://example.com')
# Locate a checkbox or radio button element
checkbox = driver.find_element(By.ID, 'checkbox_id')
# Check if the checkbox is selected
if checkbox.is_selected():
print("The checkbox is selected.")
else:
print("The checkbox is not selected.")
# Close the browser
driver.quit()
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.implicitly_wait(20)
driver.maximize_window()
# Open dummy website on the browser
driver.get('https://sqatools.in/dummy-booking-website/')
# get check element
checkbox_element = driver.find_element(By.XPATH, "//table//tr[2]//input")
# check is_selected status before selecting checkbox
print("is_selected status:", checkbox_element.is_selected()) # False
checkbox_element.click()
# check is_selected status after selecting checkbox
print("is_selected status:", checkbox_element.is_selected() # True
# Close browser
driver.quit()
This method is useful when you need to verify the state of form elements before taking further action.