Can't select an element within a dropdown menu

I have this drop-down menu that’s part of a modal popup for User creation:

Here is what the source code looks like:

I am trying to select one of the roles from the drop-down menu using the “selectOptionByIndex” keyword, however, it doesn’t work. It just hangs there, unable to select the item.

Here is what I have:

WebUI.selectOptionByIndex( findTestObject( LMS/roleItemsList’), 3)

Can somebody tell me how I can fix this?

Cheers,

image.png

stuff.png

selectOptionByIndex selects elements within elements. You’ll need to use click to “select” the element you need.

Russ Thomas said:

selectOptionByIndex selects elements within elements. You’ll need to use click to “select” the element you need.

I’ve also tried click after Focusing on the drop-down box but it doesn’t seem to work.

Have you tried either WebUI.selectOptionByLabel or WebUI.selectOptionByValue?

Jum-Ho

You’re not making it clear what is not working. Going by your HTML, I can only see the elements that appear in the dropdown once it has been opened and “dropped down”. Is the problem…

1 - Clicking on the “Choose a role” header?

Or,

2 - Clicking on “Administator”?

I can’t see from the HTML how to advise for #1… your image doesn’t show the “Choose a role” section of the HTML.

For #2, I would make the click target the element. Perhaps the

  • element would work, too, I don’t know. But since the element contains the text of the option, it should receive the click with no issues.
  • Either way, you definitely do NOT want to use any of the selectOptionXXX APIs, they only work with Select/Option elements (and you don’t have any in that HTML).

    Russ

    1 Like

    Russ Thomas said:

    Jum-Ho

    You’re not making it clear what is not working. Going by your HTML, I can only see the elements that appear in the dropdown once it has been opened and “dropped down”. Is the problem…

    1 - Clicking on the “Choose a role” header?

    Or,

    2 - Clicking on “Administator”?

    I can’t see from the HTML how to advise for #1… your image doesn’t show the “Choose a role” section of the HTML.

    For #2, I would make the click target the element. Perhaps the

  • element would work, too, I don’t know. But since the element contains the text of the option, it should receive the click with no issues.
  • Either way, you definitely do NOT want to use any of the selectOptionXXX APIs, they only work with Select/Option elements (and you don’t have any in that HTML).

    Russ

    Hello,

    My apologies, I am referring to clicking on “Administrator” from the drop-down menu. I have tried what you suggested, and it doesn’t register the click. I have tried changing the focus to the drop-down frame and calling the click keyword, but that seems to fail as well.

    I will try different methods, but if you have any ideas, please let me know.

    Cheers,

    Update:

    I had a silly typo in my code that was referring to a different element on the page. I’m very sorry about the miscommunication. Fixing it and applying Russ’ suggestion has solved my problem.

    Thank you!

    Cheers,

    You’re welcome. Glad you got it working :slight_smile:

    2 Likes