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

Aulis Ronkainen
2001 gold badge3 silver badges10 bronze badges
asked Jan 21, 2021 at 23:47
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 Commented Jan 22, 2021 at 0:18
  • How about without clicking? driver.execute_script("document.getElementById('ddlRetentionCategory').value=\"2 years\"") Commented Jan 22, 2021 at 21:57
  • you have the website link? Commented Jan 23, 2021 at 12:56

1 Answer 1

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() 
answered Jan 23, 2021 at 13:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.