我试图在下拉框中使用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和
id_asset
来查找下拉列表然后你可以使用
CSS_SELECTOR
查找下拉列表中的所有选项。然后迭代下拉列表,并查找每个options (text)
。对于本例,第一个选项为UN-POA-1875 (15) | Bærbar | Lenovo L590 20Q7 i5-8265U 1.6 GHz 8 GB 256 SSD
,然后设置if条件,如果它包含所需的文本,则选择它如果在你的问题中
代表1875,您可以替换上面的行
到
请尝试使用以下xpath,而不是
Select
:请尝试以下代码:
相关问题 更多 >
编程相关推荐