How to select value from dropdown button

Hi

Please help! I am new to automation.
I am trying to set the selected value of a dropdown. As per the source code, the dropdown is a button. I am able to click the button and display the dropdown list with below keyword
Click Button id:ha-select-target-31

How do I set the selected value to ‘Invoice No’ from the list. Please see screenshot of source and dropdown below.


image

Thanks and regards
Deboleena

1 Like

Hi @deboleena.k and welcome to the forum!

I would first try with e.g.

  Click Element  xpath: //ha-item[@label="Document ID"]

Hi Teppo

I tried this and getting error: ElementNotInteractableException: Message: element not interactable

Any other suggestion or examples please.

Thanks and regards
Deboleena

If you have the selenium library you can use the select from list functions… more info here: Targeting dropdown elements in web applications

Hi, @deboleena.k!

One possible issue could be that your selector matches more elements than you expect.

Fictional example:

Consider MDN Web Docs.

Assume your CSS selector is like this:

a[href="/en-US/docs/Learn"] (you want to find the link that has that value for the href attribute)

If you run that selector in the browser console, returning all the matches:

document.querySelectorAll('a[href="/en-US/docs/Learn"]')

…you’ll notice that it matches multiple elements:

NodeList(3) [ a, a, a ]

0: <a tabindex="-1" href="/en-US/docs/Learn" role="menuitem">
1: <a href="/en-US/docs/Learn">
2: <a href="/en-US/docs/Learn">

Assume the first of those elements is hidden for some reason. That would result in the error you mentioned.

You expected to find the element you saw (just the one), but since multiple elements were found (and you did not expect those), that can result in this scenario.

  • Check that your selector matches only the element you want.
  • If not, try to modify the selector so it matches only the element you want.

Another possibility is that it takes some time after the menu button is clicked for the item to become visible.

You could try using the Click Element When Visible keyword.

Yes. I got the same issue with GLPI Drop down menu that load the content of the dropdown menu via an Ajax request.
Didn’t solve it yet… :face_with_raised_eyebrow:

To know if that’s the case, you can use the inspector of your browser and check the Network tab to see if there is any Ajax request made when you click on the dropdown button.

Hi @deboleena.k,

Was this issue ever resolved? If not, what issues are you still having?

Best,
Tim