0
<div id="sbGlobalNav" class="">
  <div id="sbGlobalNavContent">
    <div id="sbGlobalNavRightContent">...</div>
    <div id="sbGlobalNavLeftContent">
 <a href="/" id="globalNavSBLogo"></a>
       <ul id="globalNavMenu">
     <li class="globalNavSeparator firstSeparator">..</li>
     <li>..</li>
     <li>..</li>
     <li>..</li>
     <li>..</li>
     <li class="globalNavDropdown">
    <span>Answer</span>
    <ul class="globalNavDropdownContainer" style="display: none;">
        <li>..</li>
        <li><a href="/p/polls" class="navIconPolls">Daily Polls</a></li>
        <li>..</li>
    </ul>
     </li>
     <li class="globalNavDropdown">..</li>
     <li class="globalNavSeparator">..</li>
     <li class="globalNavDropdown" id="globalNavRewards">..</li>
<div class="clear"></div>

在此我需要使用 Selenium webdriver(java) 查找并单击 Daily Poll 链接,但我无法做到。我所做的是:

        Actions builder = new Actions(driver);
    builder.moveToElement(driver.findElement(By.xpath("//div[@id='sbGlobalNav']//span[text()='Answer']"))).build().perform();
    driver.findElement(By.linkText("Daily Polls")).click(); 
4

2 回答 2

0

检查它,您是否必须这样做才能触发该元素。Javascript 也许,通过鼠标悬停?

于 2013-04-15T14:50:48.093 回答
0

尝试这个:

driver.findElement(By.xpath("//*[text()='Daily Polls']")).click(); 

它可能会起作用。

于 2013-04-15T16:41:56.527 回答