Javascript选择器:查找对应兄弟文本的复选框 [英] Javascript Selector: Find Checkbox for corresponding Sibling Text

查看:37
本文介绍了Javascript选择器:查找对应兄弟文本的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在进行测试自动化.我们需要在 kendo-grid-columnlist 下找到元素,并在 Span 中给定文本输入(产品类型),然后找到其对应的 Input Checkbox

We are doing Test Automation. We need to locate elements under kendo-grid-columnlist, and given a Text Input (Product Type) in Span, locate its corresponding Input Checkbox.

因此,如果是要求",则单击产品类型"的复选框.找到跨度ProductType,并找到其对应的输入.如何使用Javascript或Selenium FindElement Selector完成此操作?

So if Requirements, is click checkbox for "Product Type," find the span ProductType, and find its corresponding input. How can this be done with Javascript or Selenium FindElement Selector?

输入:产品类型"在kendo-grid-columnlist下

Input: "Product Type" under kendo-grid-columnlist

输出:输入复选框的对应元素

Output: Corresponding element for input checkbox

推荐答案

您可以执行以下操作,

let spans = document.querySelectorAll('kendo-grid-columnlist .k-checkbox-label');
let myElement = null;
spans.forEach(item => {
        if(item.innerText === 'Product Type') {
            myElement = item.parentNode.firstElementChild;
        }
});
console.log(myElement);

这篇关于Javascript选择器:查找对应兄弟文本的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆