<div class="form-horizontal">
<div class="row">
<div class="col-sm-3">
<label for="Url_url_option1">Option 1</label>
</div>
<div class="col-sm-1">
<input type="checkbox" data-yesno-name="Url_option1" class="url-field-toggle">
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
<input id="Url_option1" name="Url.url_option1" type="hidden" value="no">
</div>
<div class="col-sm-3">
<label for="Url_option2">Option 2</label>
</div>
<div class="col-sm-1">
<input type="checkbox" data-yesno-name="Url_option2" class="url-field-toggle">
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
<input id="Url_option2" name="Url.option2" type="hidden" value="no">
</div>
<div class="col-sm-3">
<label for="Url_option3">Option 3</label>
</div>
<div class="col-sm-1">
<input type="checkbox" data-yesno-name="Url_option3" class="url-field-toggle">
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
<input id="Url_option3" name="Url.option3" type="hidden" value="no">
</div>
</div>
<div class="row">
<div class="col-sm-12">
</div>
</div>
<div class="row">
<div class="col-sm-3">
<label for="Url_option4">Option 4</label>
</div>
<div class="col-sm-1">
<input type="checkbox" data-yesno-name="Url_option4" class="url-field-toggle">
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
<input id="Url_option4" name="Url.option4" type="hidden" value="no">
</div>
<div class="col-sm-3">
<label for="Url_option5">Option 5</label>
</div>
<div class="col-sm-1">
<input type="checkbox" data-yesno-name="Url_option5" class="url-field-toggle">
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
<input id="Url_option5" name="Url.option5" type="hidden" value="no">
</div>
<div class="col-sm-3">
<label for="Url_option6">Option 6</label>
</div>
<div class="col-sm-1">
<input type="checkbox" data-yesno-name="Url_option6" class="url-field-toggle">
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
<input id="Url_option6" name="option6" type="hidden" value="no">
</div>
</div>
</div>
所有的复选框元素apepar都是唯一的,所以我可以使用标准的定位器来查找每个复选框,但是,当我尝试单击它们中的任何一个时,我可以出现“Element not found”异常。
“隐藏”类型是否阻止单击这些按钮?
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
通过使用xpath定位器:
//*[@id="toggle_undefined"]
这行得通。click事件成功地触发到复选框,但这显然只会触发对页面上第一个元素(复选框)的单击。
假设我想使用这个xpath定位器单击第二行中的第二个复选框,如何使xpath对于页面上的每个元素(复选框)是唯一的?
在上面的HTML代码中,这是第二行的第二个复选框:
<div class="col-sm-3">
<label for="Url_option5">Option 5</label>
</div>
<div class="col-sm-1">
<input type="checkbox" data-yesno-name="Url_option5" class="url-field-toggle">
<span class="glyphicon clickable glyphicon-remove" id="toggle_undefined"></span>
<input id="Url_option5" name="Url.option5" type="hidden" value="no">
</div>