我想使用selenium webdriver验证子菜单链接名称。有人可以帮我创建一个功能吗?请在下面找到我的源代码。
<div class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse in">
<ul class="nav navbar-nav">
<li><a href="/AgentWeb/secured/home.xhtml">Home</a></li>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">My Business <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/AgentWeb/secured/agentHierarchy.xhtml">Agent Hierarchy</a></li>
<li><a href="/AgentWeb/secured/bob/newBusinessSearch.xhtml">Pending New Business</a>
</li>
<li><a href="/AgentWeb/secured/bob/inforceBusinessSearch.xhtml">Book of Business</a>
</li>
<li><a href="/AgentWeb/secured/commissions/commissionsDefault.xhtml">Commissions</a></li>
<li><a href="/AgentWeb/secured/licenseRenewals.xhtml">License Renewals</a></li>
<li><a href="/AgentWeb/secured/bob/trialAppPolicySearch.xhtml">Trial Applications</a></li>
</ul></li>
答案 0 :(得分:0)
你键入了错误的xpath,试试这个
List<WebElement> dropdowns = driver.findElements(By.xpath("//ul[@class = 'dropdown-menu']//a"));
System.out.println(dropdowns.size());
for (WebElement dropdown : dropdowns) {
System.out.println(dropdown.getText());
}