如何点击具有“策略搜索”值的元素,该值具有每个用户的动态属性,因此请帮我设置下面代码的xpath。
<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>
<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown">Policy Search <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-submenu"> <a tabindex="-1" href="#">Book of Business Search</a>
<ul class="dropdown-menu">
<li><a href="/AgentWeb/secured/clientSearch.xhtml">Client Search</a>
</li>
<li><a href="/AgentWeb/secured/policybobSearch.xhtml">Policy Search</a>
</li>
<li><a href="/AgentWeb/secured/advanceSearch.xhtml">Advanced Search</a>
</li>
</ul>
</li>
</ul>
答案 0 :(得分:0)
By.xpath("//a[contains(@class="dropdown-toggle" and text()="Policy Search")]));
如果您有多个具有相同值的项目,则可以将其指定为
By.xpath("//a[contains(text()="Policy Search")][1]));
By.xpath("//a[contains(text()="Policy Search")][2]));