Search code examples
seleniumfindelement

When trying to capture xpath of checkbox, ::before is getting highlighted, How do I capture xpath?


enter image description here

[enter image description here][3]

driver.find_element_by_xpath("//div[@class='form-group field-user-terms required']/label").click()

I tried with the above xpath, instead of selecting checkbox. It is clicking on "Terms and conditions" link


Solution

  • Try setting an implicit wait of maybe 10 seconds

    driver.implicitly_wait(10)
    

    OR

    Set an explicit wait. An explicit waits is code you define to wait for a certain condition to occur before proceeding further in the code

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "myXpath")))
    
    element.click();
    

    OR

    element = driver.find_element(By.XPATH,"yourXpath")
    driver.execute_script("arguments[0].click();", element)