我正在尝试编写一个选择一个元素然后单击该元素的测试。在Chrome中,可以看到可以通过将鼠标悬停在::before
上来定位该元素,但是xpath不能将其识别为有效的定位器。
我感兴趣的html是:
<custom-checkbox ng-model="additionalOption.isSelectedForReorder"
data-selenium-id="AquasoftTrialCheckbox_AutoReorder_true_IsTrialOnly_false"
value="AquaSoft Daily 15pk" ng-change="vm.additonalOptionSelected(additionalOption)"
accessibility-label="Select brand"
class="ng-untouched ng-valid ng-isolate-scope ng-not-empty ng-dirty ng-valid-parse"
aria-invalid="false" style="">
<div class="CustomCheckbox Radiobox">
<input ng-attr-id="{{vm.id}}" type="checkbox" ng-disabled="vm.isDisabled" id="293515277">
<label ng-attr-for="{{vm.id}}" ng-transclude="" for="293515277">
::before
<span class="d-none ng-binding ng-scope">Select brand</span>
</label>
</div>
</custom-checkbox>`
我尝试使用by.xpath("//custom-checkbox[@data-selenium-id='AquasoftTrialCheckbox_AutoReorder_true_IsTrialOnly_false']")
by.xpath("//custom-checkbox[@data-selenium-id='AquasoftTrialCheckbox_AutoReorder_true_IsTrialOnly_false']/div/input"
by.xpath("//custom-checkbox[@data-selenium-id='AquasoftTrialCheckbox_AutoReorder_true_IsTrialOnly_false']"/div/label/span
和by.xpath("//custom-checkbox[@data-selenium-id='AquasoftTrialCheckbox_AutoReorder_true_IsTrialOnly_false']/div/label/::before"
当我尝试第一个错误时,我会收到一个点击拦截错误,而其他错误只是说他们找不到该元素。