繁体   English   中英

Select 在 Python Selenium 中具有不同 id 的多个下拉菜单

[英]Select multiple drop down menus with different id's in Python Selenium

我正在尝试填写一个表格,其中每个订单号都有一个下拉菜单。

<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>

我使用什么路径来 select 多个具有不同名称的元素,所以我可以遍历它们选择我的选项。

使用contains function:

elements = driver.find_elements_by_xpath("//select[contains(@name, 'order') and contains(@name, 'shippingmethod')]")

使用以下定位器策略识别<select>节点:

  • 使用css_selectorid属性:

     elems = driver.find_elements_by_css_selector("select[id^='order'][id*='box'][id$='shippingmethod']")
  • 使用css_selectorname属性:

     elems = driver.find_elements_by_css_selector("select[name^='order'][name*='box'][name$='shippingmethod']")
  • 使用xpathname / id属性:

     elems = driver.find_elements_by_xpath("//select[starts-with(@name, 'order') and contains(@id, 'shippingmethod')]")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM