gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 05:54:55 34 4
gpt4 key购买 nike

我有一个网页:

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

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com