【发布时间】:2021-11-06 19:06:27
【问题描述】:
我正在尝试在下拉框中使用 Select() 到 find an element。但我想输入部分文本并让它搜索元素是否包含它
Python
thisValue= 1875
thisElemenet = Select(browser.find_element_by_id('id_asset'))
thisElemenet.select_by_value(str(thisValue))
我的选择脚本
<select name="asset" class="form-control" id="id_asset">
<option value="" selected="">---------</option>
<option value="235">UN-POA-1875 (15) | Bærbar | Lenovo L590 20Q7 i5-8265U 1.6 GHz 8 GB 256 SSD</option>
<option value="221">UN-POA-1929 (01) | Bærbar | Lenovo L490 20Q5 Core i5 8GB 256GB SSD</option>
</select>
如果我正在搜索 1875,我希望它找到第一个选项。
【问题讨论】:
-
可以用其他方法解决吗?而不是使用
Select。 -
不一定是我需要使用的 Select()。如果我搜索 1875,我只需要 Selenium 来选择第一个选项
-
搜索是什么意思?同样在选择中,您正在传递
id_location,其中 id 为id_asset。 -
修复了 id_asset 错误。我的意思是其中一个选项中的文本包含 1875。我希望能够通过传递字符串 1875 来选择该元素