有没有一种方法可以使用 xpath 来搜索部分值动态变化的值?

Is there a way to use xpath to search for a value where a part of the value dynamically changes?

我正在尝试匹配一个我不一定每次都知道整个值的值,即它是随机生成的。有没有办法搜索部分值动态变化的值?

请查看我试图找到的价值示例和我尝试的 xPath:

<div class="target" testid="target”>
<h2>Hi, random user</h2>
<p>To get the xpath <b>target</b> of <b>[text I don’t know]</b> in <b>[text I don’t know]</b>, you need to do the following</p>
</div>

我尝试了从另一个问题中获取的以下 xpath,但没有匹配:

//p[matches(.,'^To get the xpath <b>target</b> of <b>.*</b> in <b>.*</b>, you need to do the following$')]

我尝试了有和没有粗体标签的不同组合,但似乎无法匹配。老实说,我不确定我的语法是否正确...

为什么不使用 contains() 使用固定属性值的方法?
类似于:

//p[contains(.,'you need to do the following')]

尝试在 matches 的第二个参数中使用纯文本,例如

//p[matches(., '^To get the xpath target of .*? in .*?, you need to do the following$')]

在线样本here.