<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();