1

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?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Roman
  • 45
  • 5

2 Answers2

0

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()

TiMoFey
  • 1
  • 1
0

To verify that the checkbox is present ideally you need to induce WebDriverWait for the presence_of_element_located() and you can use either of the following locator strategies:

  • Using XPATH:

    element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[2]/div/div/div[2]/div[1]/div/div/div[1]/div/ul/li[2]")))
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352