Your first approach could work but first you should open the drop-down menu, because before that the list item is not visible or might not even exists.
Click Element #locator of the drop-down button/list
Click Element id=B & C
Your second approach is not working because the Select from List by Index
keyword expects two parameters.
Selects options from selection list locator
by indexes
.
Indexes of list options start from 0.
You did not pass the locator
of the list, which can be an xPath expression or CSS selector and you did not pass a valid index neither. Instead you have passed the locator of the list item.
In both cases you need the locator of the list itself first, and then you can select a list item with one of the keywords below.
Select From List By Label to match by text. (<div class="header-arrow itemname">B & C
</div>
)
Select From List By Label id:listId B & C
Select From List By Value to match by value. (<input type="radio" id="B & C" name="industry_type" value="B & C">
)
Select From List By Value id:listId B & C
But all of this will work only if your list has <list>
tag and the list items have <select>
tags. Based on the library source code.
def _get_select_list(self, locator):
el = self.find_element(locator, tag='list')
return Select(el)
For example with a drop-down list, with simple list-item elements: <li>
, the following error would occur:
Message: Select only works on <select>
elements, not on <li>
This would lead back to a custom solution instead of the rarely usable Select From List ...
keywords. Here is an example you can try here on SQA.
*** Settings ***
Library SeleniumLibrary
*** Variables ***
${SE HELP LOCATOR} //a[@class='-link js-help-button']
Select Element From Se Help Dropdown
[Arguments] ${item label}
# Open drop-down
Click Element ${SE HELP LOCATOR}
# Click on item to select
Click Element //li/a[contains(text(),'${item label}')]
# Optionally close the drop-down here if needed
# Click Element ${dropdown locator}
*** Test Cases ***
Select From List Example
[Tags] SQA
[Setup] Open Browser https://sqa.stackexchange.com/ Firefox
Maximize Browser Window
Set Selenium Speed 0.1
Select Element From Se Help Dropdown Help Center
Location Should Be https://sqa.stackexchange.com/help
[Teardown] Close Browser
Based on this you should be able to create your own keyword for your own drop-down.