我想點擊我的路由器網頁中的「無線」鏈接使用硒python webdriver。下面是HTML:無法點擊網頁中的鏈接使用硒webdriver
<html>
<head>
<frameset framespacing="0" frameborder="0" border="0" rows="50,*,15">
<frame noresize="" marginheight="0" marginwidth="0" target="_self" scrolling="no" border="0" frameborder="no" name="logofrm" src="logo.html">
<frameset border="0" frameborder="0" cols="170,*">
<frame noresize="" marginheight="0" marginwidth="0" target="_self" scrolling="no" border="0" frameborder="no" name="menufrm" src="menu.html">
<html>
<head>
<body class="mainMenuBody" marginwidth="0" marginheight="0" leftmargin="0" topmargin="0">
<table cellspacing="0" cellpadding="0" border="0" height="100%">
<tbody>
<tr>
<td width="1" style="background-color: #C35822"></td>
<td class="menu" width="170" valign="top" align="left">
<br>
<script language="javascript">
<div id="folder0">
<div id="folder1" style="display: block;">
<div id="folder2" style="display: none;">
<div id="folder3" style="display: none;">
<div id="folder4" style="display: none;">
<div id="item5" style="display: none;">
<div id="item6" style="display: none;">
<div id="item7" style="display: none;">
<div id="item8" style="display: none;">
<div id="folder9" style="display: none;">
<div id="folder10" style="display: none;">
<div id="folder11" style="display: none;">
<div id="folder12" style="display: block;">
<div id="folder13" style="display: none;">
<div id="item14" style="display: none;">
<div id="item15" style="display: none;">
<div id="item16" style="display: none;">
<div id="folder17" style="display: none;">
<div id="item18" style="display: none;">
<div id="folder19" style="display: none;">
<div id="item20" style="display: none;">
<div id="item21" style="display: none;">
<div id="item22" style="display: none;">
<div id="folder23" style="display: none;">
<div id="folder24" style="display: none;">
<div id="item25" style="display: none;">
<div id="item26" style="display: none;">
<div id="folder27" style="display: none;">
<div id="folder28" style="display: none;">
<div id="folder29" style="display: none;">
<div id="folder30" style="display: none;">
<div id="folder31" style="display: none;">
<div id="folder32" style="display: none;">
<div id="item33" style="display: none;">
<div id="item34" style="display: none;">
<div id="folder35" style="display: none;">
<div id="item36" style="display: none;">
<div id="item37" style="display: none;">
<div id="item38" style="display: none;">
<div id="item39" style="display: none;">
<div id="folder40" style="display: none;">
<div id="item41" style="display: none;">
<div id="item42" style="display: none;">
<div id="folder43" style="display: none;">
<div id="folder44" style="display: none;">
<div id="folder45" style="display: none;">
<div id="folder46" style="display: none;">
<div id="folder47" style="display: none;">
<div id="item48" style="display: none;">
<div id="item49" style="display: none;">
<div id="item50" style="display: none;">
<div id="item51" style="display: none;">
<div id="folder52" style="display: none;">
<div id="folder53" style="display: block;">
<table cellspacing="2" cellpadding="0" border="0" width="100%">
<tbody>
<tr>
<td class="menuCell" width="100%" valign="middle" nowrap="">
<a class="menuLink" onclick="javascript:clickOnFolder(53)" target="basefrm" href="wlswitchinterface0.wl"> Wireless </a>
</td>
</tr>
</tbody>
</table>
</div>
<div id="item54" style="display: block;">
<div id="item55" style="display: block;">
<div id="item56" style="display: block;">
<div id="item57" style="display: block;">
<div id="item58" style="display: block;">
<div id="item59" style="display: block;">
<div id="folder60" style="display: block;">
<div id="folder61" style="display: block;">
<div id="folder62" style="display: none;">
<div id="item63" style="display: none;">
<div id="item64" style="display: none;">
<div id="item65" style="display: none;">
<div id="folder66" style="display: none;">
<div id="folder67" style="display: none;">
<div id="folder68" style="display: none;">
<div id="folder69" style="display: none;">
<div id="folder70" style="display: none;">
<div id="item71" style="display: none;">
<div id="item72" style="display: none;">
<div id="folder73" style="display: none;">
<div id="folder74" style="display: none;">
<div id="folder75" style="display: none;">
<noscript>You must enable JavaScript in your browser.</noscript>
</td>
<td width="1" style="background-color: #C35822"></td>
<td style="background-color: #ffffff"></td>
</tr>
</tbody>
</table>
</body>
</html>
</frame>
<frame noresize="" marginheight="16" marginwidth="0" target="_self" scrolling="auto" border="0" frameborder="no" name="basefrm" src="info.html">
</frameset>
<frame noresize="" marginheight="0" marginwidth="0" target="_self" scrolling="no" border="0" frameborder="no" name="footerfrm" src="footer.html">
</frameset>
</html>
我有我的腳本以下行:
driver.find_element_by_xpath('//a[@href="wlswitchinterface0.wl"]').click()
但它不工作,並拋出NoSuchElementException異常
NoSuchElementException異常:消息:找不到元素: {「method」:「xpath」,「selector」:「// a [@href = \」wlswitchinterface0.wl \「]」}
它的工作原理。謝謝@Striter。但是我想知道爲什麼Selenium IDE生成的代碼無法處理這些幀切換? –
這是因爲Selenium IDE不關心框架,它可以看到整個網頁。 Selenium WebDriver一次只能關注一幀。 – Mobrockers
由於框架(或iframe)意味着與上下文基礎不同的上下文。 –