Selenium嵌套li div菜单选择()或点击()python [英] Selenium nested li div menu select() or click() python
问题描述
topMenuItem4> ul:nth-child(2)> li:nth-child(6)> a:nth-child(1)> span:nth-child(1)
我尝试了多种方法来完成这个任务,但到目前为止,我还没有能够选择或点击配置服务器链接。
试过这个:
browser.find_element_by_css_selector('#topMenuItem4> ul:nth-child(2)> li:nth-child(6)> a:nth-child(1)> span:nth-child(1)')。点击()
和这个:
browser.find_elements_by_xpath(// div [contains(@class, '包含(@ class,'Provisioning Server')])
这里是下拉菜单的截图
http:/ /screencast.com/t/81EQFAO7c
以下是来源:
<?xml version =1.0encoding =utf-8standalone =no?>
<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Strict // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
< html xmlns =http://www.w3.org/1999/xhtmlxml:lang =enlang =en>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title> Polycom - SoundPoint IP 450配置工具< / title>
< link rel =stylesheethref =css / main_page.csstype =text / css/>
< link rel =stylesheethref =css / page_content.csstype =text / css/>
< script type =text / javascriptsrc =js / jquery.js>< / script>
< script type =text / javascriptsrc =js / util.js>< / script>
< script type =text / javascriptsrc =js / main_page.js>< / script>
< script type =text / javascriptsrc =js / page_content.js>< / script>
< script type =text / javascriptsrc =js / configurator.js>< / script>
< meta http-equiv =Cache-Controlcontent =no-cache/>
< meta http-equiv =Pragmacontent =no-cache/>
< meta http-equiv =Expirescontent =0/>
< / head>
< body>
< div id =header>
< div id =logohdr>
< img src =images / logo.png/>
< span class =leftBordered>
SoundPoint IP 450
< / span>
< / div>
< div id =langHeader>
< span textId =122> < /跨度>
< select id =langaugeId>
< option value =en-in>英语内部(en-in)< / option>
< option value =zh-cn>简体中文(zh-cn)< / option>
< option value =da-dk> Dansk(da-dk)< / option>
< option value =nl-nl> Nederlands(nl-nl)< / option>
< option value =en-us>英语(en-us)< / option>
< option value =fr-fr>Français(fr-fr)< / option>
< option value =de-de> Deutsch(de-de)< / option>
< option value =it-it> Italiano(it-it)< / option>
< option value =ja-jp>日本语(ja-jp)< / option>
< option value =pt-br>Português(pt-br)< / option>
< option value =ru-ru>Русский(ru-ru)< / option>
< option value =sl-si> Slovenski(sl-si)< / option>
< option value =es-es>Español(es-es)< / option>
< option value =sv-se> Svenska(sv-se)< / option>
< option value =zh-cht>繁体中文(zh-cht)< / option>
< / select>
< / div>
< / div>
< div id =navigation>
< ul id =utility-nav>
< li>
< a href =javascript :;类= rightBordered >
< span textId =677> < /跨度>
Admin
< / a>
< / li>
< li src =登出>
< a href =login.htm>
< span textId =678> < /跨度>
< / a>
< / li>
< / ul>
< ul id =primary-nav>
< li src =home.htmid =topMenuItem1>
< a href =javascript:;>
< span textId =96> < /跨度>
< / a>
< / li>
< li src =simpleSetup.htmid =topMenuItem2>
< a href =javascript:;>
< span textId =201> < /跨度>
< / a>
< / li>
< li class =menu-itemid =topMenuItem3>
< a href =javascript:;>
< span textId =190> < /跨度>
< / a>
< ul>
< li src =datetimeConf.htm>
< a href =javascript:;>
< span textId =57> < /跨度>
< / a>
< / li>
< li src =sampConf.htm>
< a href =javascript:;>
< span textId =218> < /跨度>
< / a>
< / li>
< li src =bgConfMedGray.htm>
< a href =javascript:;>
< span textId =24> < /跨度>
< / a>
< / li>
< li src =presence.htm>
< a href =javascript:;>
< span textId =534> < /跨度>
< / a>
< / li>
< li src =othersConf.htm>
< a href =javascript:;>
< span textId =171> < /跨度>
< / a>
< / li>
< / ul>
< / li>
< li class =menu-itemid =topMenuItem4>
< a href =javascript:;>
< span textId =242> < /跨度>
< / a>
< ul>
< li src =browConf.htmcheckFeature =MB>
< a href =javascript:;>
< span textId =146> < /跨度>
< / a>
< / li>
< li src =logConf.htm>
< a href =javascript:;>
< span textId =135> < /跨度>
< / a>
< / li>
< li src =applConf.htm>
< a href =javascript:;>
< span textId =8> < /跨度>
< / a>
< / li>
< li src =codecprefConf.htm>
< a href =javascript:;>
< span textId =12> < /跨度>
< / a>
< / li>
< li src =audioCodecProfConf.htm>
< a href =javascript:;>< span textId =9> < /跨度>编解码器配置文件< / a>
< / li>
< li src =provConf.htm>
< a href =javascript:;>
< span textId =316> < /跨度>
< / a>
< / li>
< li src =syslogConf.htm>
< a href =javascript:;>
< span textId =533> < /跨度>
< / a>
< / li>
< li class =menu-item-2>
< a href =javascript:;>
< span textId =152> < /跨度>
< / a>
< ul>
< li src =qosConf.htm>
< a href =javascript:;>
< span textId =197> < /跨度>
< / a>
< / li>
< li src =rtpConf.htm>
< a href =javascript:;>
< span textId =204> < /跨度>
< / a>
< / li>
< li< li src =natConf.htm>
< a href =javascript:;>
< span textId =150> < /跨度>
< / a>
< / li>
< li src =tcpConf.htm>
< a href =javascript:;>
< span textId =253> < /跨度>
< / a>
< / li>
< li src =sslSecurityConf.htm>
< a href =javascript:;>
< span textId =228> < /跨度>
< / a>
< / li>
< li src =ethernetConf.htm>
< a href =javascript:;>
< span textId =329> < /跨度>
< / a>
< / li>
< / ul>
< / li>
< li src =pttConf.htm>
< a href =javascript:;>
< span textId =473> < /跨度>
< / a>
< / li>
< li src =sipConf.htm>
< a href =javascript:;>
< span textId =531> < /跨度>
< / a>
< / li>
< li class =menu-item-3src =reg_1.htmdisplaySubMenuInLeftPanel =1>
< a href =javascript:;>
< span textId =125> < /跨度>
< / a>
< ul>
< li src =reg_1.htm>
< a href =javascript:;>< span textId =123> < /跨度> 1·; / A>
< / li>
< li src =reg_2.htm>
< a href =javascript:;>< span textId =123> < /跨度> 2'; / A>
< / li>
< li src =reg_3.htm>
< a href =javascript:;>< span textId =123> < /跨度> 3'; / A>
< / li>
< / ul>
< / li>
< li src =userAccountConf.htm>
< a href =javascript:;>
< span textId =271> < /跨度>
< / a>
< / li>
< li src =phoneLockConf.htm>
< a href =javascript:;>
< span textId =178> < /跨度>
< / a>
< / li>
< / ul>
< / li>
< li class =menu-itemid =topMenuItem5>
< a href =javascript:;>
< span textId =62> < /跨度>
< / a>
< ul>
< li src =viewlogs.htm>
< a href =javascript:;>
< span textId =283> < /跨度>
< / a>
< / li>
< / ul>
< / li>
< li class =menu-itemid =topMenuItem6>
< a href =javascript:;>
< span textId =276> < /跨度>
< / a>
< ul>
< li src =importexportconf.htm>
< a href =javascript:;>
< span textId =111> < /跨度>
< / a>
< / li>
< li src =phoneBackupRestore.htm>
< a href =javascript:;>
< span textId =177> < /跨度>
< / a>
< / li>
< li src =upgrade.htm>
< a href =javascript:;>
< span textId =246> < /跨度>
< / a>
< / li>
< li src =Soft_Key_configTool.htm>
< a href =javascript:;>
< span textId =285> < /跨度>
< / a>
< / li>
< li src =Line_Key_configTool.htm>
< a href =javascript:;>
< span textId =536> < /跨度>
< / a>
< / li>
< li src =restartPhone.htm>
< a href =javascript:;>
< span textId =214> < /跨度>
< / a>
< / li>
< li src =rebootPhone.htm>
< a href =javascript:;>
< span textId =209> < /跨度>
< / a>
< / li>
< / ul>
< / li>
< / ul>
< / div>
< div id =breadcrumbs>
< p />
< / div>
< div id =wrapper>
< div id =navclass =nav>
< div id =phoneimage>
< p />
< / div>
< ul>
< li>
< div>
< span textId =673> < /跨度>
< / div>
< ul />
< / li>
< / ul>
< / div>
< div id =contentclass =content>
< div id =pageContent>
< p />
< / div>
< div id =btnCnt_static_pg>
< div id =buttonContentclass =button-group>
< button class =button gray mediumonclick =resetForm()toolTipId =271>
< span textId =584/>
< / button>
< button class =button gray mediumonclick =resetToDefaults()toolTipId =272>
< span textId =1002/>
< / button>
< button class =button gray mediumonclick =viewModifications()toolTipId =273>
< span textId =1003/>
< / button>
< button class =button gray mediumonclick =submitForm()toolTipId =274>
< span textId =574/>
< / button>
< / div>
< / div>
< / div>
< div id =supp-infoclass =supp-info>
< ul class =tree>
< li>
< a href =javascript :;类= 选择 >
< span textId =674> < /跨度>
< / a>
< ul>
< li>
< div style =height:130px; overflow-y:scroll;/>
< / li>
< / ul>
< / li>
< li>
< a href =javascript:;>
< span textId =675> < /跨度>
< / a>
< / li>
< li>
< a href =javascript:;>
< span textId =676> < /跨度>
< / a>
< / li>
< / ul>
< / div>
< / div>
< div id =modalDialog> < / DIV>
< div id =darken> < / DIV>
< span id =showStartPagestyle =display:none;>
< / span>
< div class =popupid =popupdlgstyle =display:none>
< div class =top-bar>
< / div>
< div class =popup-content>
< p />
< / div>
< div class =btn-popup-actions>
< p />
< / div>
< / div>
< span id =isChinesePhonestyle =display:none>
0
< / span>
< div class =previewpopupid =previewpopupdlgstyle =display:none/>
< / body>
< / html>
li [src ='provConf.html'] a
。 我也不确定linkText是否可行,但我认为它是更具描述性的,如果它的工作。
最后,因为它是一个下拉菜单,它需要行动链像理查德说。 b
topMenuItem4 > ul:nth-child(2) > li:nth-child(6) > a:nth-child(1) > span:nth-child(1)
I have tried a variety of methods to accomplish this but I so far have not been able to select or click the provisioning server link.
Tried this: browser.find_element_by_css_selector('#topMenuItem4 > ul:nth-child(2) > li:nth-child(6) > a:nth-child(1) > span:nth-child(1)').click()
and this:
browser.find_elements_by_xpath("//div[contains(@class,'menu-item') and (contains(.,'topMenuItem4'))]//div[contains(@class,'Provisioning Server')]")
Here is a capture of the drop down menu
http://screencast.com/t/81EQFAO7c
Here is the source:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Polycom - SoundPoint IP 450 Configuration Utility</title>
<link rel="stylesheet" href="css/main_page.css" type="text/css"/>
<link rel="stylesheet" href="css/page_content.css" type="text/css"/>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/util.js"></script>
<script type="text/javascript" src="js/main_page.js"></script>
<script type="text/javascript" src="js/page_content.js"></script>
<script type="text/javascript" src="js/configurator.js"></script>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
</head>
<body>
<div id="header">
<div id="logohdr">
<img src="images/logo.png"/>
<span class="leftBordered">
SoundPoint IP 450
</span>
</div>
<div id="langHeader">
<span textId="122"> </span>
<select id="langaugeId">
<option value="en-in">English Internal (en-in)</option>
<option value="zh-cn">简体中文 (zh-cn)</option>
<option value="da-dk">Dansk (da-dk)</option>
<option value="nl-nl">Nederlands (nl-nl)</option>
<option value="en-us">English (en-us)</option>
<option value="fr-fr">Français (fr-fr)</option>
<option value="de-de">Deutsch (de-de)</option>
<option value="it-it">Italiano (it-it)</option>
<option value="ja-jp">日本語 (ja-jp)</option>
<option value="ko-kr">한국어 (ko-kr)</option>
<option value="no-no">Norsk (no-no)</option>
<option value="pl-pl">Polski (pl-pl)</option>
<option value="pt-br">Português (pt-br)</option>
<option value="ru-ru">Русский (ru-ru)</option>
<option value="sl-si">Slovenski (sl-si)</option>
<option value="es-es">Español (es-es)</option>
<option value="sv-se">Svenska (sv-se)</option>
<option value="zh-cht">繁體中文 (zh-cht)</option>
</select>
</div>
</div>
<div id="navigation">
<ul id="utility-nav">
<li>
<a href="javascript:;" class="rightBordered">
<span textId="677"> </span>
Admin
</a>
</li>
<li src="logout">
<a href="login.htm">
<span textId="678"> </span>
</a>
</li>
</ul>
<ul id="primary-nav">
<li src="home.htm" id="topMenuItem1">
<a href="javascript:;">
<span textId="96"> </span>
</a>
</li>
<li src="simpleSetup.htm" id="topMenuItem2">
<a href="javascript:;">
<span textId="201"> </span>
</a>
</li>
<li class="menu-item" id="topMenuItem3">
<a href="javascript:;">
<span textId="190"> </span>
</a>
<ul>
<li src="datetimeConf.htm">
<a href="javascript:;">
<span textId="57"> </span>
</a>
</li>
<li src="sampConf.htm">
<a href="javascript:;">
<span textId="218"> </span>
</a>
</li>
<li src="bgConfMedGray.htm">
<a href="javascript:;">
<span textId="24"> </span>
</a>
</li>
<li src="presence.htm">
<a href="javascript:;">
<span textId="534"> </span>
</a>
</li>
<li src="othersConf.htm">
<a href="javascript:;">
<span textId="171"> </span>
</a>
</li>
</ul>
</li>
<li class="menu-item" id="topMenuItem4">
<a href="javascript:;">
<span textId="242"> </span>
</a>
<ul>
<li src="browConf.htm" checkFeature="MB">
<a href="javascript:;">
<span textId="146"> </span>
</a>
</li>
<li src="logConf.htm">
<a href="javascript:;">
<span textId="135"> </span>
</a>
</li>
<li src="applConf.htm">
<a href="javascript:;">
<span textId="8"> </span>
</a>
</li>
<li src="codecprefConf.htm">
<a href="javascript:;">
<span textId="12"> </span>
</a>
</li>
<li src="audioCodecProfConf.htm">
<a href="javascript:;"><span textId="9"> </span> Codec Profiles</a>
</li>
<li src="provConf.htm">
<a href="javascript:;">
<span textId="316"> </span>
</a>
</li>
<li src="syslogConf.htm">
<a href="javascript:;">
<span textId="533"> </span>
</a>
</li>
<li class="menu-item-2">
<a href="javascript:;">
<span textId="152"> </span>
</a>
<ul>
<li src="qosConf.htm">
<a href="javascript:;">
<span textId="197"> </span>
</a>
</li>
<li src="rtpConf.htm">
<a href="javascript:;">
<span textId="204"> </span>
</a>
</li>
<li src="natConf.htm">
<a href="javascript:;">
<span textId="150"> </span>
</a>
</li>
<li src="tcpConf.htm">
<a href="javascript:;">
<span textId="253"> </span>
</a>
</li>
<li src="sslSecurityConf.htm">
<a href="javascript:;">
<span textId="228"> </span>
</a>
</li>
<li src="ethernetConf.htm">
<a href="javascript:;">
<span textId="329"> </span>
</a>
</li>
</ul>
</li>
<li src="pttConf.htm">
<a href="javascript:;">
<span textId="473"> </span>
</a>
</li>
<li src="sipConf.htm">
<a href="javascript:;">
<span textId="531"> </span>
</a>
</li>
<li class="menu-item-3" src="reg_1.htm" displaySubMenuInLeftPanel="1">
<a href="javascript:;">
<span textId="125"> </span>
</a>
<ul>
<li src="reg_1.htm">
<a href="javascript:;"><span textId="123"> </span> 1</a>
</li>
<li src="reg_2.htm">
<a href="javascript:;"><span textId="123"> </span> 2</a>
</li>
<li src="reg_3.htm">
<a href="javascript:;"><span textId="123"> </span> 3</a>
</li>
</ul>
</li>
<li src="userAccountConf.htm">
<a href="javascript:;">
<span textId="271"> </span>
</a>
</li>
<li src="phoneLockConf.htm">
<a href="javascript:;">
<span textId="178"> </span>
</a>
</li>
</ul>
</li>
<li class="menu-item" id="topMenuItem5">
<a href="javascript:;">
<span textId="62"> </span>
</a>
<ul>
<li src="viewlogs.htm">
<a href="javascript:;">
<span textId="283"> </span>
</a>
</li>
</ul>
</li>
<li class="menu-item" id="topMenuItem6">
<a href="javascript:;">
<span textId="276"> </span>
</a>
<ul>
<li src="importexportconf.htm">
<a href="javascript:;">
<span textId="111"> </span>
</a>
</li>
<li src="phoneBackupRestore.htm">
<a href="javascript:;">
<span textId="177"> </span>
</a>
</li>
<li src="upgrade.htm">
<a href="javascript:;">
<span textId="246"> </span>
</a>
</li>
<li src="Soft_Key_configTool.htm">
<a href="javascript:;">
<span textId="285"> </span>
</a>
</li>
<li src="Line_Key_configTool.htm">
<a href="javascript:;">
<span textId="536"> </span>
</a>
</li>
<li src="restartPhone.htm">
<a href="javascript:;">
<span textId="214"> </span>
</a>
</li>
<li src="rebootPhone.htm">
<a href="javascript:;">
<span textId="209"> </span>
</a>
</li>
</ul>
</li>
</ul>
</div>
<div id="breadcrumbs">
<p/>
</div>
<div id="wrapper">
<div id="nav" class="nav">
<div id="phoneimage">
<p/>
</div>
<ul>
<li>
<div>
<span textId="673"> </span>
</div>
<ul/>
</li>
</ul>
</div>
<div id="content" class="content">
<div id="pageContent">
<p/>
</div>
<div id="btnCnt_static_pg">
<div id="buttonContent" class="button-group">
<button class="button gray medium" onclick="resetForm()" toolTipId="271">
<span textId="584"/>
</button>
<button class="button gray medium" onclick="resetToDefaults()" toolTipId="272">
<span textId="1002"/>
</button>
<button class="button gray medium" onclick="viewModifications()" toolTipId="273">
<span textId="1003"/>
</button>
<button class="button gray medium" onclick="submitForm()" toolTipId="274">
<span textId="574"/>
</button>
</div>
</div>
</div>
<div id="supp-info" class="supp-info">
<ul class="tree">
<li>
<a href="javascript:;" class="selected">
<span textId="674"> </span>
</a>
<ul>
<li>
<div style="height:130px; overflow-y: scroll;"/>
</li>
</ul>
</li>
<li>
<a href="javascript:;">
<span textId="675"> </span>
</a>
</li>
<li>
<a href="javascript:;">
<span textId="676"> </span>
</a>
</li>
</ul>
</div>
</div>
<div id="modalDialog"> </div>
<div id="darken"> </div>
<span id="showStartPage" style="display:none;">
</span>
<div class="popup" id="popupdlg" style="display:none">
<div class="top-bar">
<img src="images/popup_close.png" id="popupimgclose" width="16" height="16" align="right" class="popup-closer"/>
</div>
<div class="popup-content">
<p/>
</div>
<div class="btn-popup-actions">
<p/>
</div>
</div>
<span id="isChinesePhone" style="display:none">
0
</span>
<div class="previewpopup" id="previewpopupdlg" style="display:none"/>
</body>
</html>
Using the following CSS should work: li[src='provConf.html'] a
.
I'm also not sure if linkText would work, but I think it is much more descriptive if it does work.
Finally, because it is a dropdown menu, it make require action chaining like Richard said.
这篇关于Selenium嵌套li div菜单选择()或点击()python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!