我遇到定位对象的问题
我有
<div class="form-item-pair form-group left" field="SearchGroup.Network">
<div class="form-label">
<div class="form-value">
<ng-transclude>
<div class="ui-select-container ui-select-bootstrap dropdown ng-valid" ng-class="{open: $select.open}" ng-model="vm.criteria.networkName">
<div class="ui-select-match" ng-class="{'btn-default-focus':$select.focus}" ng-disabled="$select.disabled" ng-hide="$select.open" placeholder="Select network...">
<span class="btn btn-default form-control ui-select-toggle" style="outline: 0;" ng-click="$select.activate()" ng-disabled="$select.disabled" aria-label="Select box activate" tabindex="-1">
我必须点击最后一个元素span
,如何创建最后一个跨度的路径,仅在代码中field="SearchGroup.Network"
是唯一的?
driver.findElement(By.xpath("//span[@class='btn btn-default form-control ui-select-toggle']")).click();
它不起作用,因为它不是唯一的
答案 0 :(得分:3)
您应该使用CSS选择器。要使其唯一,请添加路径中存在的一些属性:
driver.findElement(By.cssSelector(
"[field='SearchGroup.Network'] [placeholder='Select network...'] span[aria-label='Select box activate']"
)).click();
答案 1 :(得分:0)
试试这个
driver.findElement(By.xpath("//div[@class='ui-select-match']/span")).click();
或者这个
driver.findElement(By.xpath("//div[@class='ui-select-match']/following::span[1]")).click;