-1

Python is throwing error when I try to find element by ID or Class name. Please help to find which code will help to pick the data of the specific dropdown

HTML:

</div>
<div class="clslblLevelStatus">Level Status</div>
<div class="clsdrpstatus">
    <select id="levelstatusDropdownlist" class="chzn-select-deselect chzn-done" style="width: 200px; display: none;" tabindex="-1">
        <option value=""></option>
    <option value="">--All Statuses--</option><option value="0|1000">Unassigned</option><option value="1|15">L1 - Work In Progress</option><option value="1|14">L1 - Pending</option><option value="1|2">L1 - Hold</option><option value="1|1">L1 - Completed</option><option value="1|3">L1 - Invalid</option><option value="2|15">L2 - Work In Progress</option><option value="2|14">L2 - Pending</option><option value="2|2">L2 - Hold</option><option value="2|3">L2 - Invalid</option><option value="3|15">L3 - Work In Progress</option><option value="3|14">L3 - Pending</option><option value="3|2">L3 - Hold</option><option value="3|3">L3 - Invalid</option><option value="0|1001">Completed</option></select><div id="levelstatusDropdownlist_chzn" class="chzn-container chzn-container-single" style="width: 200px;" title=""><a href="javascript:void(0)" class="chzn-single chzn-default" tabindex="-1"><span>Select an Option</span><div><b></b></div></a><div class="chzn-drop" style="left: -9000px; width: 198.4px; top: 23px;"><div class="chzn-search"><input type="text" autocomplete="off" tabindex="2" style="width: 163.8px;"></div><ul class="chzn-results"><li id="levelstatusDropdownlist_chzn_o_1" class="active-result" style="">--All Statuses--</li><li id="levelstatusDropdownlist_chzn_o_2" class="active-result" style="">Unassigned</li><li id="levelstatusDropdownlist_chzn_o_3" class="active-result" style="">L1 - Work In Progress</li><li id="levelstatusDropdownlist_chzn_o_4" class="active-result" style="">L1 - Pending</li><li id="levelstatusDropdownlist_chzn_o_5" class="active-result" style="">L1 - Hold</li><li id="levelstatusDropdownlist_chzn_o_6" class="active-result" style="">L1 - Completed</li><li id="levelstatusDropdownlist_chzn_o_7" class="active-result" style="">L1 - Invalid</li><li id="levelstatusDropdownlist_chzn_o_8" class="active-result" style="">L2 - Work In Progress</li><li id="levelstatusDropdownlist_chzn_o_9" class="active-result" style="">L2 - Pending</li><li id="levelstatusDropdownlist_chzn_o_10" class="active-result" style="">L2 - Hold</li><li id="levelstatusDropdownlist_chzn_o_11" class="active-result" style="">L2 - Invalid</li><li id="levelstatusDropdownlist_chzn_o_12" class="active-result" style="">L3 - Work In Progress</li><li id="levelstatusDropdownlist_chzn_o_13" class="active-result" style="">L3 - Pending</li><li id="levelstatusDropdownlist_chzn_o_14" class="active-result" style="">L3 - Hold</li><li id="levelstatusDropdownlist_chzn_o_15" class="active-result" style="">L3 - Invalid</li><li id="levelstatusDropdownlist_chzn_o_16" class="active-result" style="">Completed</li></ul></div></div>
        
   

I have tried the below code

Queue_status = Select(browser.find_element(By.ID,'levelstatusDropdownlist'))
Queue_status.select_by_visible_text("--All Statuses--")

Queue_status = browser.find_element(By.ID,'levelstatusDropdownlist_chzn'))
Queue_status.click()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    hi, could you please share the url you are testing. Also add error message that you get in your question. thx – Manish Feb 03 '23 at 11:28

1 Answers1

0

The <select> is having the property style="width: 200px; display: none;" so you can't use the <select> tag.


Solution

To select an option you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategies:

  • Code block:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a//span[text()='Select an Option']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='chzn-drop']//ul[@class='chzn-results']//li[text()='L2 - Work In Progress']"))).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