html - 通过 xpath selenium 网络驱动程序查找元素

标签 html css xpath selenium-webdriver

我有一个网页:

  <div class="formfonttitle">Wireless - General</div>
    <div style="margin-left:5px;margin-top:10px;margin-bottom:10px"><img       src="/images/New_ui/export/line_export.png"></div>
    <div class="formfontdesc">Set up the wireless related information below.</div>
    <table width="99%" border="1" align="center" cellpadding="4" cellspacing="0" id="WLgeneral" class="FormTable">
    <tr id="wl_unit_field">
    <th>Frequency</th>
    <td>
    <select name="wl_unit" class="input_option" onChange="_change_wl_unit(this.value);">
    <option class="content_input_fd" value="0" >2.4GHz</option>
    <option class="content_input_fd" value="1" selected>5GHz</option>
    </select>
    </td>
    </tr>

我正在尝试使用 xpath 选择“2.4GHz”。默认选择“5GHz”选项。我正在使用 Python 脚本并使用 selenium webdriver 执行此操作。

我这样做:

elements = mydriver.find_element_by_xpath("//div[@class='wl_unit']")
title = elements[1].find_elements_by_xpath(".//div[@class='content_input_fd']")

但它不起作用。

最佳答案

您可以使用以下 XPath 找到 2.4GHz 选项元素,然后在该元素上执行“单击”以将其选中:

option = mydriver.find_element_by_xpath("//select[@name='wl_unit']/option[@value='0']")
option.click()

关于html - 通过 xpath selenium 网络驱动程序查找元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37114807/

相关文章:

html - 您可以使用 mailto 链接来回复电子邮件并保留线程吗?

xml - 匹配 XSLT 上的属性而不是匹配整个元素

javascript - 展开div回到原来的位置

javascript - 列出来自 HTML XPath 的项目

soap - Hive UDF for SOAP XPath?

html - 根据最长可能文本的大小更改 div 的宽度

css - 如何使用 Bootstrap 类在 Angular 5 的同一行中对齐 div

javascript - 按钮 onclick 出现重定向问题

javascript - 当图像处于事件状态时显示 div

javascript - 当您有多个表单时,IE8 不会在输入时提交