[英]XPath for an element that contains another element with certain text?
I know how to locate div
inside the button
:我知道如何在
button
内找到div
:
//button/div[contains(text(),'Save')]
I'd like to know is it possible to locate any button
which contains div with text "Save"
inside?我想知道是否可以找到任何包含带有文本
"Save"
div 的button
?
<button class="PinBetterSave__Button" data-test-id="PinBetterSaveButton"><div class="_w7 _0 _1 _2 _wa _36 _d _b _6">Save</div></button>
You can try你可以试试
//button[contains(div,'Save')]
to locate button
with child div
that contains specific text使用包含特定文本的子
div
定位button
Careful, the other answer, //button[contains(div,'Save')]
works in this case, but be aware that it will fail when小心,另一个答案
//button[contains(div,'Save')]
在这种情况下有效,但请注意它会在以下情况下失败
button
contains a span
or another or no element, rather than a div
.button
包含一个span
或另一个或没有元素,而不是一个div
。div
elements whose string values contain the substring , "Save"
: "Save this"
, "Save that"
, "Jesus Saves"
, etc.div
元素一起存在,其字符串值包含子字符串"Save"
: "Save this"
、 "Save that"
、 "Jesus Saves"
等。 This XPath,这个 XPath,
//button[normalize-space() = 'Save']
will select button
elements whose space-normalized string value is exactly "Save"
.将选择空间标准化字符串值恰好为
"Save"
button
元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.