python - 在 Python Selenium 中选择具有不同 ID 的多个下拉菜单
问题描述
我正在尝试填写一个表格,其中每个订单号都有一个下拉菜单。
<select name="order(889673519).box(1).shippingmethod" onclick="" onchange=""
id="order(889673519).box(1).shippingmethod"><option value=""
id="order(889673519).box(1).shippingmethod.blank"></option>
对于每个下拉菜单,名称 css 选择器中的数字都会改变,所以第一个是 889673519 但第二个是
<select name="order(889711159).box(1).shippingmethod" onclick="" onchange=""
id="order(889711159).box(1).shippingmethod"><option value=""
id="order(889711159).box(1).shippingmethod.blank"></option>
我使用什么路径来选择具有不同名称的多个元素,这样我就可以遍历它们来选择我的选项。
解决方案
使用contains
功能:
elements = driver.find_elements_by_xpath("//select[contains(@name, 'order') and contains(@name, 'shippingmethod')]")
推荐阅读
- mysql - 相关模型的动态范围,然后按距离排序
- python - 如何将数组中的所有对象拆分为 2 列?
- javascript - 从react Native中的userEffect中的异步函数返回一个清理函数
- javascript - javascript onClick事件找不到循环php的ID
- python - 安装pyaudio后出现ModuleNotFoundError
- bash - printf 转义码未在 Bash 脚本中格式化
- uwp - Xbox One S 启动错误:尝试从零售模式切换到开发模式时,它崩溃并出现错误系列 E200
- php - XAMPP 使用 SQLServer 更新 MSSQL 中的表,注意:数组到字符串的转换
- javascript - 如何使用 JS join() 在数组元素之前附加自定义字符串
- javascript - 访问另一个元素内的元素 JavaScript 数据