0

I am trying to control page by Selenium. I have a problem with listbox. This is how it looks:

<span title="" class="k-widget k-dropdown" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="ddlRetentionCategory_listbox" aria-live="polite" aria-disabled="false" aria-busy="false" style="" aria-activedescendant="3d9fac25-2597-4668-82d0-c00a04131818"><span unselectable="on" class="k-dropdown-wrap k-state-default"><span unselectable="on" class="k-input">--Select--</span><span unselectable="on" class="k-select" aria-label="select"><span class="k-icon k-i-arrow-60-down"></span></span></span><input id="ddlRetentionCategory" name="ddlRetentionCategory" type="text" value="" data-role="dropdownlist" style="display: none;" aria-required="true" aria-invalid="true"></span>

and this is what I need to select from dropdown/listbox:

<span title="" class="k-widget k-dropdown" unselectable="on" role="listbox" aria-haspopup="true" aria-expanded="false" tabindex="0" aria-owns="ddlRetentionCategory_listbox" aria-live="polite" aria-disabled="false" aria-busy="false" style="" aria-activedescendant="3d9fac25-2597-4668-82d0-c00a04131818"><span unselectable="on" class="k-dropdown-wrap k-state-default k-state-focused"><span unselectable="on" class="k-input">2 years</span><span unselectable="on" class="k-select" aria-label="select"><span class="k-icon k-i-arrow-60-down"></span></span></span><input id="ddlRetentionCategory" name="ddlRetentionCategory" type="text" value="" data-role="dropdownlist" style="display: none;" aria-required="true" aria-invalid="true"></span>

enter image description here

3
  • Ok I am able to open list select = driver.find_element_by_class_name('k-input').click() but I can not select 2 years Jan 22 at 0:18
  • How about without clicking? driver.execute_script("document.getElementById('ddlRetentionCategory').value=\"2 years\"")
    – pavelsaman
    Jan 22 at 21:57
  • you have the website link?
    – PDHide
    Jan 23 at 12:56
1
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.CLASS_NAME,"k-input"))).click()

WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,"//span[contain(text(),'2 years')]"))).click()

Try using wait, and if second line doesn't work use below code click the parent span tag instead

WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,"//span[contain(text(),'2 years')]/..")))

You can also use action class:

option = WebDriverWait(driver,30).until(EC.visibility_of_element_located((By.XPATH,"//span[contain(text(),'2 years')]")))

ActionChains(driver).move_to_element(option ).click().perform() 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.