如何获取列表中的所有项目

时间:2019-07-09 15:00:17

标签: robotframework

我有一个网页,其中的代码是:

<select tabindex="8" id="custom_field_4" name="custom_field_4[]" size="4" multiple="multiple" xpath="1">
    <option value="red">red</option>
    <option value="yellow">yellow</option>
    <option value="green" selected="selected"> green</option>
    <option value="flashing" selected="selected"> flashing</option>
</select>

我需要获取所有选项值。

我尝试过 获取列表项//select[@name="custom_field_4[]"],但出现错误:List with locator \'//select[@name="custom_field_4[]/option"]\' not found.'

1 个答案:

答案 0 :(得分:0)

如果您检查Selenium库的source code(第333行),您会看到Get List Items关键字使用list作为标记名,而在DOM中则为{{1 }}。不匹配。

select

您可以使用def _get_select_list(self, locator): el = self.find_element(locator, tag='list') return Select(el) 关键字来获取所有列表元素,例如:

Get WebElements

您可以访问返回列表中每个元素的${list elements}= Get WebElements //select[@id='custom_field_4']/option 属性。

相关问题