我正在尝试使用selenium webdriver自动化路由器配置。下面是路由器页面的html:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="">
<head>
<body onunload="return unload_body();" onload="initial();">
<div id="TopBanner">
<div id="Loading" class="popup_bg">
<div id="hiddenMask" class="popup_bg">
<iframe id="hidden_frame" height="0" frameborder="0" width="0" name="hidden_frame">
<form target="hidden_frame" action="/start_apply2.htm" name="autochannelform" method="post">
<form target="hidden_frame" action="/start_apply2.htm" name="form" method="post">
<input type="hidden" value="RT-N66U" name="productid">
<input type="hidden" value="" name="wan_route_x">
<input type="hidden" value="1" name="wan_nat_x">
<input type="hidden" value="Advanced_Wireless_Content.asp" name="current_page">
<input type="hidden" value="Advanced_Wireless_Content.asp" name="next_page">
<input type="hidden" value="0" name="modified">
<input type="hidden" value="apply_new" name="action_mode">
<input type="hidden" value="restart_wireless" name="action_script">
<input type="hidden" value="10" name="action_wait">
<input id="preferred_lang" type="hidden" value="EN" name="preferred_lang">
<input type="hidden" disabled="" value="US" name="wl_country_code">
<input type="hidden" value="3.0.0.4" name="firmver">
<input type="hidden" value="" name="wps_mode">
<input type="hidden" value="" name="wps_config_state">
<input type="hidden" disabled="" value="" name="wlc_ure_ssid_org">
<input type="hidden" value="" name="wl_key1_org">
<input type="hidden" value="" name="wl_key2_org">
<input type="hidden" value="" name="wl_key3_org">
<input type="hidden" value="" name="wl_key4_org">
<input type="hidden" value="" name="wl_phrase_x_org">
<input type="hidden" readonly="1" value="" name="x_RegulatoryDomain" size="15" maxlength="15">
<input type="hidden" value="off" name="wl_gmode_protection">
<input type="hidden" value="on" name="wl_wme">
<input type="hidden" value="0" name="wl_mode_x">
<input type="hidden" value="-1" name="wl_nmode">
<input type="hidden" value="1" name="wl_nmode_x_orig">
<input type="hidden" value="" name="wl_nctrlsb_old">
<input type="hidden" value="" name="wl_key_type">
<input type="hidden" value="" name="wl_channel_orig">
<input type="hidden" value="" name="wl_chanspec">
<input type="hidden" value="0" name="wl_wep_x_orig">
<input type="hidden" value="0" name="wl_optimizexbox">
<input type="hidden" value="-1" name="wl_subunit">
<input type="hidden" value="" name="acs_dfs">
<input type="hidden" value="0" name="acs_band1">
<table class="content" cellspacing="0" cellpadding="0" align="center">
<tbody>
<tr>
<td width="17"> </td>
<td width="202" valign="top">
<td valign="top">
<div id="tabMenu" class="submenuBlock">
<table cellspacing="0" cellpadding="0" border="0" align="left" width="98%">
<tbody>
<tr>
<td align="left" valign="top">
<table id="FormTitle" class="FormTitle_firefox" cellspacing="0" cellpadding="4" border="0" width="760px" style="height: 838px;">
<tbody>
<tr>
<td bgcolor="#4D595D" valign="top">
<div> </div>
<div class="formfonttitle">Wireless - General</div>
<div style="margin-left:5px;margin-top:10px;margin-bottom:10px">
<div class="formfontdesc">Set up the wireless related information below.</div>
<table id="WLgeneral" class="FormTable" cellspacing="0" cellpadding="4" border="1" align="center" width="99%">
<tbody>
<tr id="wl_unit_field">
<th>Frequency</th>
<td>
<select class="input_option" onchange="_change_wl_unit(this.value);" name="wl_unit">
<option class="content_input_fd" selected="" value="0">2.4GHz</option>
<option class="content_input_fd" value="1">5GHz</option>
</select>
</td>
</tr>
<tr>
<tr>
<tr>
<tr id="wl_bw_field">
<tr>
<tr id="wl_nctrlsb_field">
<tr>
<tr>
<tr>
<tr style="display: none;">
<tr style="display: none;">
<tr style="display: none;">
<tr style="display: none;">
<tr style="display: none;">
<tr style="display: none;">
<tr style="display: none;">
<tr style="display:none">
<tr>
</tbody>
</table>
<div class="apply_gen">
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
<td align="center" width="10" valign="top"></td>
</tr>
</tbody>
</table>
<div id="footer">
</form>
</body>
</html>
我想从“频率”下拉框中选择“5GHz”选项。以下是执行此操作的代码:
self.browser_driver.get(self.base_url)
self.browser_driver.find_element_by_id("option_str1").click()
time.sleep(1)
Select(self.browser_driver.find_element_by_css_selector("select[name=\"wl_unit\"]")).select_by_visible_text("5GHz")
time.sleep(10)
self.browser_driver.close()
但是,只要从下拉菜单中选择了5GHz
选项,我就会获得地址为router_ip/apply.cgi
的空白页。我在这个网页上看到以下消息。
“router_ip”页面无效 “router_ip”没有发送任何数据。 ERR_EMPTY_RESPONSE
如何摆脱这个问题。在手动配置路由器期间,我没有遇到此问题。
答案 0 :(得分:0)
我正在将路由器凭据添加到python脚本中的base_url,这导致页面刷新问题。从下拉菜单中选择选项后,页面刷新发生,脚本无法再次打开身份验证URL。现在我在同一会话中使用身份验证URL登录到路由器后打开base_url(没有凭据)。现在以下代码正在运行:
self.base_url = "http://"+server_ip+"/"
self.auth_url = "http://" + "login" + ":" + "password" + "@" +server_ip+"/"
self.browser_driver.get(self.auth_url)
self.browser_driver.get(self.base_url)
self.browser_driver.find_element_by_id("option_str1").click()
time.sleep(1)
Select(self.browser_driver.find_element_by_css_selector("select[name=\"wl_unit\"]")).select_by_visible_text("5GHz")
time.sleep(10)
self.browser_driver.close()