//div[@ng-if="subNav.state == 'active'"]
我尝试如下,但得到" InvalidSelectorException" :
String active = "subNav.state == 'active'";
driver.findElement(By.xpath("//div[@ng-if='"+active+"']"))
<li class="active" on="subNav.state != '' && subNav.state != 'active'" ng-switch="" ng-repeat="subNav in navigation[activeNav].pages | filter:subNavFilter(navigation[activeNav].pages)">
<div class="whereabouts ng-scope" ng-if="subNav.state == 'active'"></div>
<span class="badge badge-active" aria-disabled="true" ng-if="subNav.state != 'complete'">6</span>
<span class="ng-binding ng-scope" ng-switch-when="false">Loan</span>
</li>
&#13;
答案 0 :(得分:0)
如果在值中使用了引号,你应该转义引号。我建议用双引号来关闭所有引号。 这是xpath
String active = "subNav.state == 'active'";
driver.findElement(By.xpath("//div[@ng-if=\"" + active + "\"]"));