我有一个网页,其中的代码是:
<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.'
发布于 2019-07-10 20:18:46
如果检查Selenium库的source code (第333行),可以看到Get List Items关键字使用list作为标记名,而在DOM中是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您可以访问返回列表中每个元素的value属性。
https://stackoverflow.com/questions/56955451
复制相似问题