1

I'm trying to set up an automation that can help me work easier. I want to log in to a device automatically and set up some initial settings. The part I am having trouble with is that I have to check a checkbox to continue, but I couldn't find a way to click on the button. link

This is the XPath for that button:

//*[@id="tableHdd"]/div/div[1]/span[1]/input

broswer.find_element_by_class_name('table-cell').find_elements_by_class_name('checkbox').click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Jonas Chiu
  • 13
  • 3

2 Answers2

0

You're misusing Element Locators

So if there is only one checkbox at the page - you can tick it like:

driver.find_element_by_class_name("checkbox").click()

If there are more checkboxes and you need to tick particular that one - use slightly amended XPath expression:

driver.find_element_by_xpath("//div[@id='tableHdd']/descendant::*/span[@class='table-cell']/input").click()
Dmitri T
  • 159,985
  • 5
  • 83
  • 133
0

To clcick() on the checkbox you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div#tableHdd > div.table > div.table-header > span.table-cell > input.checkbox"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='tableHdd']/div[@class='table']/div[@class='table-header']/span[@class='table-cell']/input[@class='checkbox']"))).click()
    
  • 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