Travis Travis - 3 months ago 11
HTML Question

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)



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>

Answer

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.