如何在 java 中的 xpath 下方写入
how to write below xpath in java
//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>
如果在值中使用引号,您应该转义 quotes.And 我建议使用双引号来关闭所有引号。
这是 xpath
String active = "subNav.state == 'active'";
driver.findElement(By.xpath("//div[@ng-if=\"" + active + "\"]"));
//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>
如果在值中使用引号,您应该转义 quotes.And 我建议使用双引号来关闭所有引号。 这是 xpath
String active = "subNav.state == 'active'";
driver.findElement(By.xpath("//div[@ng-if=\"" + active + "\"]"));