How to use Select From List By Value/Label/Index using an xpath on the actual select option

Hi, I am currently completing the Certification 2 training and I am trying to select a dropdown value from RobotSpareBin Industries Inc. - Intranet.

Here are the web elements:

I want to choose the ‘Roll-a-thor head’ using an Xpath (I realize I could choose it by specifying the value being ‘1’ but I want to only use Xpaths.

Here is my code:

What is breaking is the xpath://option[contains(text(),‘Roll-a-thor head’)] phrase and I cannot figure out how to use an Xpath with this Select action.

I cannot tell if:

  • My Xpath is wrong
  • I am using the wrong Select action

Select From List By Value chooses option by its value attribute, you are passing in xpath.
If you want to select by text, you can use keyword Select From List By Label. Your xpath for dropdown looks correct.

1 Like

Thanks for the response! I tried that earlier and it still wasn’t working. When I use Select From List by Label with that selector I get the error:

Could not locate element with visible text: xpath://option[contains(text(),‘Roll-a-thor head’)]

Correct would be Select From List By Label //:select[@='head] Roll-a-thor head or
Select From List By Value //:select[@='head] 1 so argument after locator is an value not an selector

1 Like