selenium-webdriver - 如何使用量角器切换没有 id 的复选框
问题描述
我是量角器 e2e 的新手。我正在尝试切换没有 id 的复选框。如果复选框被选中,我如何获取值?
<div class="bootstrap-switch bootstrap-switch-wrapper bootstrap-switch-mini bootstrap-switch-on bootstrap-switch-animate" style="width: 62px;">
<div class="bootstrap-switch-container" style="width: 90px; margin-left: 0px;">
<span class="bootstrap-switch-handle-on bootstrap-switch-success" style="width: 30px;">Yes</span>
<span class="bootstrap-switch-label" style="width: 30px;"> </span>
<span class="bootstrap-switch-handle-off bootstrap-switch-danger" style="width: 30px;">No</span>
<input type="checkbox" data-bind="bootstrapSwitchOn: IsActive, v1:$root.isenable" data-on-text="Yes" data-off-text="No" data-size="mini" data-handle-width="20px" data-label-width="20px" data-on-color="success" data-off-color="danger">
</div>
</div>
<label class="checkbox-inline" data-bind="text: window.LabelVM.workflow_details_active,attr: { 'data-title': window.LabelVM.workflow_details_active, 'data-con': window.LabelVM.Active_popover, 'data-popover': 'popover' }" data-tab="3" data-orientation="right" data-title="Is Active" data-con="Activate your workflow for it to appear in Self Service. If a Workflow isn&#39;t active, it cannot be accessed by a staff member" data-popover="popover">Is Active</label>
解决方案
You should try making your check to be based on the presence of the bootstrap-switch-on
class that I assume indicates that the checkbox is set/checked.
Something along these lines:
function checkValue (checkbox) {
checkbox.getAttribute("class").then(function (classes) {
var switchOn = classes.indexOf("bootstrap-switch-on") >= 0;
if (switchOn) {
console.log("Switch is on");
} else {
console.log("Switch is off");
}
});
}
var checkbox = $(".bootstrap-switch");
checkValue(checkbox);
checkbox.click();
checkValue(checkbox);
(not tested)
推荐阅读
- c# - c#中switch语句的伪代码
- javascript - 接收 Socket.IO 消息 2 次
- javascript - 将 Javascript 对象数组转换为 google.maps.LatLng 对象数组
- javascript - 通过 beforeunload 跟踪自定义加载栏的加载进度
- azure - 使用 Terraform azure 添加应用程序作为贡献者
- youtube-data-api - youtube api nextPageToken 仍然返回结果
- swift - NSScrollView 不滚动
- php - Goutte 无法提交表单
- rxjs - BehaviourSubject 的先前值
- javascript - ejs变量不显示用户名