1

What I need:

  • Select one of the options from the drop-down list
  • Only BUTTON element is visible (SELECT element is not visible)

This is html code:

<td data-bind="css: { 'cell-error': applicantNames.hasError }, attr: { title: applicantNames.message }" title="">
    <select data-bind="options: $parent.applicants, multivalue: applicantNames" multiple="multiple" style="display: none;">
        <option value="ABC">ABC</option>
        <option value="XYZ">XYZ</option>
    </select>
    <button type="button" class="ui-multiselect ui-widget ui-state-default ui-corner-all" aria-haspopup="true" style="width: 236px;"><span class="ui-icon ui-icon-triangle-2-n-s"></span><span>Please select...</span></button>
</td>

This is how it looks like:

enter image description here

The problem is that I would like to select one of these options by using Selenium, but because the SELECT element is not interactable/not visible ... not sure what to do...

If you will choose an option from the drop-down the BUTTON element will be updated like this

<button type="button" class="ui-multiselect ui-widget ui-state-default ui-corner-all ui-state-active" aria-haspopup="true" style="width: 236px;">
    <span class="ui-icon ui-icon-triangle-2-n-s"></span><span>ABC, XYZ</span>
</button>

Even if I will update the BUTTON section manually, it will still not update the element visually..... so I'm a bit stuck to find a way how to interact with these elements by using Selenium...

P.S. I'm looking for ANY headless methods, e.g. Selenium / JavaScript execution through selenium and e.t.c...

1 Answer 1

1

See the problem is that "This is not built using Select - option tag", so one can not directly make use of Select class from Selenium support package.

Instead you can try to click on that menu using Selenium .click() in your case something like this

driver.find_element_by_xpath("//span[contains(text(), 'Please select')]").click()

and then store all the visible option in a list of web elements using find_elements and then iterate the list :

for option in list_of_options:
    if option.text == "your desired option"
       option.click()
Sign up to request clarification or add additional context in comments.

4 Comments

I just found the problem, this list of options actually appeared inside the frame ..... a strange way of coding, but anyway..... so I found a way to go into this page, get visible elements and find the correct option. P.S. not sure if I need to close/delete this question
Probably you'd need to switch over to iframe.
Your answer is good :) but the key will be that the actual option list is located in a different place (not where you believe they should be)
@OksanaOk : Generally we get NoSuchElementException in case of iframe. Since it was not mentioned I did not think that it could be in an iframe. Well good luck !

Your Answer

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.