0
我想選擇頻道在下拉框使用selenimum webdriver(Python)的網頁。下面HTML給出:如何使用硒webdriver從下拉框中選擇
<iframe id="page" frameborder="0" src="DashBoard.htm" onfocus="this.blur()" scrolling="no" cellspacing="0" border="0" name="page" style="width: 1076px; height: 525px; margin-left: 30px; margin-top: 0px; visibility: visible;">
<!DOCTYPE html>
<html>
<head>
<body class="page-body" onresize="change_size();" onload="change_size();initScrn();setKeys();showWpsAlert();highLightMenu('setup_header', 'wireless_set');">
<img class="cover-image" src="img/cover-image_noh.gif" style="display: none;">
<img class="body-image" src="img/subhead2-background_noh.jpg" style="width: 1076px; height: 495px; position: absolute; top: 5px;">
<div id="full-page-container">
<form id="target" action="wireless.cgi?id=1484693214" method="POST">
<input type="hidden" name="buttonHit">
<input type="hidden" name="buttonValue">
<img class="subtop-image" src="img/subhead2-top_noh.gif" style="width: 1076px; height: 32px;">
<div class="subhead2"> Wireless Setup</div>
<table class="subhead2-table" border="0" style="height: 405px; position: relative; top: -3px; width: 1049px;">
<tbody>
<tr valign="middle" align="left">
<tr>
<td class="scrollpane-table-seperate-border" colspan="2">
<div class="scroll-pane" style="height: 405px; width: 1049px; overflow: auto;">
<table style="border-collapse:collapse;width:97%">
<tbody>
<tr>
<tr>
<tr>
<tr>
<td colspan="2">
<div id="setting_2G" style="display: block;">
<table cellspacing="0" cellpadding="0" border="0" width="100%" <table="">
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<td nowrap="">Channel:</td>
<td nowrap="">
<select size="1" name="w_channel">
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
</tbody>
</table>
</div>
</td>
</tr>
<tr valign="middle" align="center">
</tbody>
</table>
<img class="subfooter-image" src="img/subhead2-bottom.gif" style="width: 1076px; height: 24px; position: relative; top: -3px;">
<div class="subhead2-bottom" style="width: 1076px;">
<input type="hidden" value="0" name="tempSetting">
<input type="hidden" value="5" name="tempRegion">
<input type="hidden" value="17" name="setRegion">
<input type="hidden" value="0" name="wds_enable">
<input type="hidden" value="0" name="wds_enable_an">
<input type="hidden" value="0" name="only_mode">
<input type="hidden" value="0" name="show_wps_alert">
<input type="hidden" value="WPA-AUTO-PSK" name="security_type_2G">
<input type="hidden" value="WPA-AUTO-PSK" name="security_type_5G">
<input type="hidden" value="WPA-AUTO-PSK" name="init_security_type_2G">
<input type="hidden" value="WPA-AUTO-PSK" name="init_security_type_5G">
<input type="hidden" value="11" name="initChannel">
<input type="hidden" value="automatic" name="initAuthType">
<input type="hidden" value="0" name="initDefaultKey">
<input type="hidden" value="161" name="initChannel_an">
<input type="hidden" value="automatic" name="initAuthType_an">
<input type="hidden" value="0" name="initDefaultKey_an">
<input type="hidden" value="1" name="telec_dfs_ch_enable">
<input type="hidden" value="0" name="ce_dfs_ch_enable">
<input type="hidden" value="0" name="fcc_dfs_ch_enable">
<input type="hidden" value="1" name="auto_channel_5G">
<input type="hidden" value="1" name="support_ac_mode">
<input type="hidden" value="U12H270T00_NETGEAR" name="board_id">
<input type="hidden" value="0" name="enable_band_steering">
<input type="hidden" value="SKU_WW" name="fw_sku">
<input type="hidden" value="0.0.0.0" name="wla_radius_ipaddr">
<input type="hidden" value="0.0.0.0" name="wlg_radius_ipaddr">
<input type="hidden" value="WPA-AUTO" name="wla_ent_secu_type">
<input type="hidden" value="WPA-AUTO" name="wlg_ent_secu_type">
<input type="hidden" value="192.168.0.100" name="wan_ipaddr">
<input type="hidden" value="255.255.255.0" name="wan_netmask">
<a name="helpframe-anchor"></a>
</form>
</div>
<meta content="R7000" name="description">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta content="text/css" http-equiv="Content-Style-Type">
<meta content="no-cache" http-equiv="Pragma">
<meta content="no-cache" http-equiv="Cache-Control">
<meta content="Mon, 06 Jan 1990 00:00:01 GMT" http-equiv="Expires">
</body>
</html>
</iframe>
我有以下Python代碼:
driver.find_element_by_css_selector("#WLS_menu > span").click()
Select(driver.find_element_by_name("w_channel")).select_by_visible_text("12")
driver.find_element_by_name("Apply").click()
我收到以下錯誤:
File "netgear", line 23, in test_netge Select(driver.find_element_by_name("w_channel")).select_by_visible_text("12")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: {"method":"name","selector":"w_channel"}
我失去了我的代碼的東西嗎?
從錯誤它看起來,它無法找到元素a首先使用名稱「w_channel」。 –
嗨耶謝謝,我已經更新了我的答案,請看看現在它是否工作 –
不工作。它引發此錯誤: NoSuchElementException:消息:無法找到元素:{「method」:「xpath」,「selector」:「// * [@ id ='setting_2G']/table/tbody/tr [5]/td [2]/select「} –