我有以下HTML
代码:
<li class="ng-scope" ng-repeat="option in RentTenantPreference.options">
<label class="ng-binding">
<input class="ng-scope ng-pristine ng-valid ng-touched" type="checkbox" checklist-value="option.id" ng-disabled="fieldLocks['RentPref']" ng-model="checked" checklist-model="formObj.occ_r" style=""/>
Family
</label>
</li>
我正在尝试使用//label[contains(text(),'Family')]
xpath找到标签,但无法执行此操作。
答案 0 :(得分:1)
尝试以下方法:
$("#enquiryForm").submit(function (e) {
var formData = $('#enquiryForm').serializeArray();
$.post(
"/CarDealer/Enquiry", formData, function (data) {
debugger;
if (data["IsSucceeded"] == true) {
// code here
}
else{
// code here
}
document.getElementById("enquiryForm").reset();
}, 'json');
return false;
});
答案 1 :(得分:0)
html有些混乱,不知道到底是什么,但你可以尝试不同的方法,选择所有标签元素并检查他们的文本是否包含&#39; Family&#39; :
label_elements = browser.find_elements_by_xpath('.//label')
for label_element in label_elements:
if 'Family' in label_element.text:
#dosomething with current element(label_element)
我希望这种解决方法能够满足您的需求。
答案 2 :(得分:0)
尝试使用以下xpath中的任何一个,因为Text位于&#39;输入&#39;标签
// label [descendant :: input [contains(text(),&#39; Family&#39;)]](留在标签字段中)
或
// label / input [contains(text(),&#39; Family&#39;)](移动到标签内的输入字段)
答案 3 :(得分:-1)
您似乎错过了正确的xPath 使用下面的代码 -
.//*[contains(text(),'Family')]
希望它会对你有所帮助。