实习生:使用 For 属性查找动态生成的 ID

Intern: Finding Dynamically Generated ID's Using For Attribute

我将 Intern 与一个动态生成输入框、按钮、菜单项等 ID 的网站一起使用。我面临的问题是我希望能够找到 "for"标签的属性并找到它指向的 DOM 元素。我想找到与标签关联的输入。实习生可以吗?或者我将如何编写这个测试用例?

     <div> 
<label for="element_1x12">
</label>
<input id="element_1x12">
</input>
<label for="element_1x13">
</label>
<input id=element_1x13">
</input>
    </div>

假设你有办法 select 元素,你可以这样做:

// find the label somehow
.findByCssSelector(...)
.getAttribute('for')
.then(function (value, setContext) {
    return this.parent
        // pop the previously found element off the context stack
        .end()
        // find the input, which has an id equal to the label's for
        .findById(value)
        // set the context to the found input
        .then(function (input) {
            setContext(input);
        });
})
// do stuff with the input