python - 选择选项值不起作用

标签 python select selenium option

这是我的测试HTML:

    <tr>
      <td >
        <select>
          <option selected="selected" value="0">0</option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
        </select>
     </td>
   </tr>


和我的代码像

select_el=driver.find_element_by_xpath("//select") 
Select(el_select).select_by_visible_text('1')


味精没有错误,但选项值未更改?有人可以给我一些建议吗?

以这个网站为例:https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss

driver.get("https://www-01.ibm.com/products/hardware/configurator/americas/bhui/launchNI.wss")
driver.find_element_by_id("modelnumber").send_keys('7383AC1')
driver.find_element_by_name("submit").click()
el_inputs=driver.find_elements_by_name('CID_CONTROL_VideoAdapter_MultiSelect')
FC='A1QU'
for el_input in el_inputs:
    el_td=el_input.find_element_by_xpath("..")
    if FC in el_td.get_attribute('innerHTML'):
            print el_td.get_attribute('innerHTML')
            el_tr=el_td.find_element_by_xpath("..")
            el_select=el_tr.find_element_by_xpath("//select")
            Select(el_select).select_by_visible_text('1')

最佳答案

您应该使用.//select xpath而不是//select。这将在表格行中找到适当的select标记。

关于python - 选择选项值不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18099403/

相关文章:

python - 如何在 Tensorflow 张量的每行和每列中选取前 q 个元素?

sql - 使用连接和解码在子选择中排序

mysql - 在 MySQL 中合并 2 个计数

java - 在Selenium Java中从列表中选择随机元素并单击它,但getAttribute不等于0

java - 从示例中找不到 Selenium 类名

python - 在字典和 numpy 数组中查找最大值的性能

python - 为 Python 包使用日历版本控制

python - GAE- Mechanize 源代码

mysql - 如何从非唯一键检索不匹配的记录?

ruby - Selenium Ruby - 按类属性切换框架