Unable to select Option from Select

I have this simple HTML File:

I am trying to select option 3 with

click xpath=//html/body/select

click xpath=//html/body/select/option[3]

The first click opens the select box, but the second click always fails.
My thougt was that i have to first click on the select to open it, second click on Option 3

I can see that the select is clicked, because it opens up.

I trid the forec=true in click

The Error i am getting is:

Error: locator.click: Element is not visible
=========================== logs ===========================
waiting for locator(ā€˜xpath=//html/body/select/option[3]’)
locator resolved to option value=ā€œ1ā€ 1 /option
attempting click action
waiting for element to be visible, enabled and stable
forcing action
element is visible, enabled and stable
scrolling into view if needed

I also tried to set the focus on the Option.
But I always get the ā€˜Element is not visible’ Error.
I have no clue what the problem is.
Thanks

Hi Jochen,

Just curious, Is there a reason for not using the Select Options By keyword?

Dave.

Hi Dave,
if i try
Select Options By xpath=//select index 3
nothing happens.
I would expect that option 3 gets selected but nothing.
Maybe i don’t understand Select Option By.

Just read the Documentation there it says:

Returns list of options which keyword was able to select. The type of list item matches to attribute definition. Example if attribute equals to label returned list contains label values. Or in case of index it contains list of selected indexes.<

So i guess Select Option By is not what i need

Thanks
Jochen

Hi,

Did you tried the following (I assume you’re trying to click on value ā€œ1" which is the third option below the select:

  • Click xpath=//html/body/select[@class=’gsmui_field’]/option[3]
  • Click xpath=(//select[@class=’gsmui_field’]/option)[3]
  • Click xpath=//select[@class=’gsmui_field’]/option[@value=’1’]
  • Add a bit of wait/sleep between clicks just to confirm
  • Get the text from the option you’re trying to target, to verify what is found

Regards

Charlie

Solved it.
a simple
Select Option by xpath//select Value 3
got the Job done.

Maybe my Error was that i first clicked the select or that i used index instead of value.

Thanks Dave and Charlie.
Jochen

2 Likes

Hi @maui ,

If you don’t want to use Select Option By, try this approach:
Click Element //*[@value=ā€œ3ā€]
If that works, I recommend using a variable to make it more reusable.
For example:
Click Element //
*[@value=ā€œ${variable}ā€]
Another option could be by text:
Click Element //*[text(),ā€œ${variable}ā€]

I hope that hepls!

Regard

Lucas

Hi @lmarlaire,
thanks for your reply.

I am using the Browser Library not Silenium.
I am afraid Click Element is not available in the Browser Library.

If i change the Click Element to Click it is not working.
That was my initial problem.
But the Select Option by did the trick.

Thank you anyway for your support.

Jochen

1 Like