沿着这篇 MDN 文章的思路,我有一个由三个不同元素的组合标记的复选框输入:一个标签、一个文本字段,然后是另一个标签。
因此,复选框输入有一个aria-labelledby属性,其值类似于label1 text-field label2。
<input type="checkbox" aria-labelledby="allow-up-to num words-in-between" />
<div>
<label id="allow-up-to">allow up to</label>
<input id="num" type="text" value="0" />
<label id="words-in-between">words in between</label>
</div>
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我尝试根据该标签获取复选框。
getByLabelText('text of label1')我可以使用或成功获取输入getByLabelText('text of label2'),但为其提供完整的串联标签getByLabelText('text of label1 value of text-field text of label2')会导致找不到任何内容。
getByLabelText("allow up to"); // works
getByLabelText("words in between") // works
getByLabelText("allow up to 0 words in between") // does not work
Run Code Online (Sandbox Code Playgroud)
尝试getByLabelText('value of text-field')也不起作用,但即使我从 中删除文本字段aria-labelledby,我仍然无法使用 …
I have an XML file that represents the syntax trees of all the sentences in a book:
<book>
<sentence>
<w class="pronoun" role="subject">
I
</w>
<wg type="verb phrase">
<w class="verb" role="verb">
like
</w>
<wg type="noun phrase" role="object">
<w class="adj">
green
</w>
<w class="noun">
eggs
</w>
</wg>
</wg>
</sentence>
<sentence>
...
</sentence>
...
</book>
Run Code Online (Sandbox Code Playgroud)
This example is fake, but the point is that the actual words (the <w> elements) are nested in unpredictable ways based on syntactic relationships.
What I'm trying to …