这是最离奇的事情。我一直在使用XPATH来选择不同的菜单选项(我有Eclipse NEON和最新的Selenium)
你可以在附图中看到,我可以精美地选择带有XPATH的前3个链接。为什么最后三个会失败?我也会包含代码。我试过找到链接,这也不起作用。
<div id="rightColumn">
<div class="simplemenu accord ui-accordion ui-widget ui-helper-reset" id="accordion" role="tablist">
<h5 class="headerbar first ui-accordion-header ui-corner-top ui-state-default ui-accordion-header-active ui-state-active" role="tab" id="ui-id-1" aria-controls="ui-id-2" aria-selected="true" aria-expanded="true" tabindex="0">Films & Versions</h5>
<div style="display: block;" class="ui-accordion-content ui-corner-bottom ui-helper-reset ui-widget-content ui-accordion-content-active" id="ui-id-2" aria-labelledby="ui-id-1" role="tabpanel" aria-hidden="false">
<ul>
<li><a href="/filmAdmin.php"><img src="/images/film.png" border="0"> Film Admin</a></li>
<li><a href="/filmVersionAdmin.php"><img src="/images/film_link.png" border="0"> Film Version Admin</a></li>
<li><a href="/filmVersionMaccsCode.php"><img src="/images/film_error.png" border="0"> Film versions without DCHub ref</a></li>
<li><a href="/filmVersionsWithNoTers.php"><img src="/images/film_save.png" border="0"> Film Versions With No Territories</a></li>
<li><a href="/matchFilmVWithMPS.php"><img src="/images/film_go.png" border="0"> Match Film Version With MPS</a></li>
<li><a href="/maccsCPLNames.php"><img src="/images/magnifier_zoom_in.png" border="0"> Duplicate MACCS Film Strings</a></li>
</ul>
</div>
答案 0 :(得分:0)
尝试使用以下元素定位器来定位最后3个元素:
driver.findElement(By.cssSelector("div#rightColumn > div div >ul li:nth-child(3) > a"));
driver.findElement(By.cssSelector("div#rightColumn > div div >ul li:nth-child(4) > a"));
driver.findElement(By.cssSelector("div#rightColumn > div div >ul li:nth-child(5) > a"));