1

I am new to Selenium and I am learning the basics. I want to select a checkbox on the page with this python code:

    driver.find_element_by_xpath("//div[@id='checkbox1']").click()

Unfortunately this approach does not work. I get an error from Selenium saying that function click() does not exist for the webelement. The div element in the html page is defined like this:

    <div role="checkbox" id="checkbox1"></div>

What other functions exists (similar to click()) to select the checkbox.

Matej Kalc
  • 11
  • 3

1 Answers1

2

On the HTML you provided the element is a div not an input but that really does not matter. You should be able to do this:

driver.find_element_by_id('checkbox1').click()

You mentioned you were getting an error when clicking the element. Could you share that error? Im guessing that it must be something like Element not clickable at point [...] or Element not visible

If thats the case, make sure that the element is displayed in the view port before you interact with it. You can use Action chains or javascript to move to the element. Take a look at this thread

eduardoreynoso
  • 240
  • 3
  • 9