Reputation: 668
I wish to mark a checkbox, but the problem is that that text near the checkbox also incorporates a collapse-link, so whenever I try and click it, only the drop-down text is shown so the checkbox isn't being marked. I've tried clicking the checkbox using
driver.find_element_by_xpath(".//*[contains(text(), 'example_text_positiond_next_to_checkbox')]").click()
but this, as mentioned, only clicks the text, which then proceeds to display the collapsed text
the HTML snippet is (and I hope I haven't missed any important part)
<label class="custom-control-label"
for="customCheck1"><a class="collapse-link collapsed"
data-toggle="collapse" href="#collapseInfo" role="button" aria-expanded="false"
aria-controls="collapseExample">example_text_positiond_next_to_checkbox<span
class="arrow"></span></a></label>
I've thought of somehow clicking some margin to the left of the text, but not quite sure how to do so. any suggestions are welcomed!
Upvotes: 0
Views: 92
Reputation: 39
This can be done with css selector, as there is no direct way to inspect that checkbox in DOM.
driver.find_element(By.CSS_SELECTOR,"input#customCheck1.custom-control-input").click()
try below css.
input#customCheck1.custom-control-input
Upvotes: 0
Reputation: 19979
driver.get("https://corona.health.gov.il/en/green-pass/")
driver.find_element_by_css_selector('[for="customCheck1"]').click()
input()
you can use any attribute to find element the above locator with attribute 'for' will work. You can use xpath or css
XPATH equalent:
//*[@for="customCheck1"]
Upvotes: 1