-1

I have started learning Selenium using python. I want to click checkbox (Workdays 10-11). Please refer respective HTML Tag as shown below. I have tried using Xpath but id in the tag keeps changing every execution. Also, I have tried using Class name but no-use.Can you please advice?

<div id="EAACAAA_b3" xscroll="1" onmouseleave="hidetreepager(this.firstChild)" onmouseenter="showtreepager(this.firstChild,event.srcElement,event)" onmousemove="showtreepager(this.firstChild,event.srcElement,event)" style="width: 347px; height: 300px; overflow: auto;"><div id="members_tree" treeid="members" mode="crittree" multiselect="true" autowidth="true" enabled="" class="xcriteriadropdown-members" onclick="clickcrittree(this,event)" singleselect="03344C6E"><div class="treenoderoot" nodeid="0" state="1"><span class="treetext"><span></span><img src="images/blank.gif" style="display:none"><img src="images/checkbox_checked.png" align="absmiddle" class="treestate"><a href="#">No selection</a></span><div class="treechildren" style="display:block;padding-left:0px" id="ext-gen8"><div class="treenode" nodeid="1" state="0" id="ext-gen10"><div class="treetext"><img src="images/blank.gif" nalign="absmiddle"><img src="images/checkbox_unchecked.png" class="treestate" nalign="absmiddle"><a href="#">Workdays 10-11</a></div></div><div class="treenode" nodeid="2" state="0"><div class="treetext"><img src="images/blank.gif" nalign="absmiddle"><img src="images/checkbox_unchecked.png" class="treestate" nalign="absmiddle"><a href="#">Workdays 08-10, 11-16</a></div></div><div class="treenode" nodeid="3" state="0"><div class="treetext" id="ext-gen11"><img src="images/blank.gif" nalign="absmiddle"><img src="images/checkbox_unchecked.png" class="treestate" nalign="absmiddle"><a href="#">Workdays 00-08, 16-24</a></div></div><div class="treenode" nodeid="4" state="0" id="ext-gen9"><div class="treetext" id="ext-gen7"><img src="images/blank.gif" nalign="absmiddle"><img src="images/checkbox_unchecked.png" class="treestate" nalign="absmiddle"><a href="#">Weekends and holidays</a></div></div></div></div></div><img src="resource.ashx?resname=Misc_Down16&amp;_dc=" 76d3ff65"="" border="0" style="position: absolute; left: -5000px; top: -5000px;" id="ext-gen5"><img src="resource.ashx?resname=Misc_Up16&amp;_dc=" 76d3ff65"="" border="0" style="position: absolute; left: -5000px; top: -5000px;" id="ext-gen6"></div>

enter image description here

<div class="treenode" nodeid="1" state="0" id="ext-gen11"><div class="treetext" id="ext-gen8"><img src="images/blank.gif" nalign="absmiddle"><img src="images/checkbox_unchecked.png" class="treestate" nalign="absmiddle" id="ext-gen7"><a href="#" id="ext-gen12">Workdays 10-11</a></div></div>
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Please don't change the question based on which you have received well researched answers. Once you receive canonical answers changing the question can make all the existing answers invalid and may not be useful to future readers. If your requirement have changed feel free to raise a new question. StackOverflow contributors will be happy to help you out. For the time being I have reverted back the question to it's initial state. – undetected Selenium Mar 24 '23 at 20:50

2 Answers2

0

To identify the element Workdays 10-11 use following xpath.

//a[text()='Workdays 10-11']

Code:

  driver.find_element(By.XPATH, "//a[text()='Workdays 10-11']").click()
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

To click on the element with text as Workdays 10-11 you can use either of the following locator strategies:

  • Using link_text:

    driver.find_element(By.LINK_TEXT, "Workdays 10-11").click()
    
  • Using xpath:

    driver.find_element(By.XPATH, "//a[text()='Workdays 10-11']").click()
    

Ideally to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Workdays 10-11"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='Workdays 10-11']"))).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