I am trying to access the following HTML checkbox for a button click:
JavaScript
x
2
1
<input type="checkbox" data-ng-value="sf.name" data-ng-model="sf.checked" ng-click="ec.onStateFilterChanged(sf)" title="Select a state" class="ng-untouched ng-valid ng-dirty ng-valid-parse" value="Arizona">
2
using:
JavaScript
1
2
1
state = driver.find_element_by_xpath("input[@type='checkbox']").click()
2
but keep getting error:
JavaScript
1
2
1
selenium.common.exceptions.NoSuchElementException: Message:
2
what might be the element path I am looking for in order to select the checkbox?
Advertisement
Answer
Your xpath is most likely incorrect – you need to enter //
before the element as this will find all (single slash /
will work here too though as you are only trying to find one element and it will find the first match)
Try one of the following:
JavaScript
1
2
1
state = driver.find_element_by_xpath("//input[@type='checkbox']").click()
2
OR
JavaScript
1
2
1
state = driver.find_element_by_css_selector("input[type='checkbox']").click()
2