'Is there any option to verify/assert element CheckBox is present using Selenium Python

I'm trying to verify that the checkbox is present but didn't find the exact answer is it possible to check it using Selenium Python (Assert will be great solution).

This is my code:

driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div[1]').click()
time.sleep(1)
driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div[1]/div/div/div[1]/div/ul/li[2]').click()

Now I need to verify whether element with xpath:

/html/body/div[2]/div/div/div[2]/div[1]/div/div/div[1]/div/ul/li[2]

is present ot not?



Solution 1:[1]

if you want to check state of object, you can use is_selected() function.

driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div[1]').is_selected()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TiMoFey