I'm trying to use python & Selenium to click on a slider/checkbox on a website and I'm having a lot of difficulty. I can simply find the element by ID (1369) and click on it no worries, except the ID numbers change dynamically over time so they are proving pretty much useless to me.
I also tried finding the element by class, XPath, etc. and clicking on it using many questions posted to Stack Overflow as reference with no luck, as there seems to be some differences in the HTML code in my scenario that are stopping me from progressing. Any help would be greatly appreciated thank you!
Reference HTML as text:
<div class="f-box vcbox">
<span class="text-item box-item">Single date</span>
<div id="1369" class="checkbox checbox-switch switch-primary ">
<label>
<em class="fake-input "></em>
<span>
::before
</span>
</label>
</div>
Reference HTML code on website
Code that works when the ID is known in advance:
driver.find_element(By.ID, "1369").click()
Code that hasn't worked:
driver.find_element(By.CSS_SELECTOR, 'em.checkbox checbox-switch switch-primary').click()
driver.find_element(By.CSS_SELECTOR, 'div.checkbox.checbox-switch.switch-primary').click()
driver.find_element(By.XPATH, "//span[contains(.,'Single date')]").click()