java如何将2个xpath合并为一个
Html
<li class="wdappchrome-ai" data-automation-id="searchInputAutoCompleteResult" tabindex="-2" aria-posinset="1" aria-setsize="3">
<span data-automation-id="searchInputAutoCompleteResultFullText">
<span style="font-weight:500">
<span data-automation-id="searchInputAutoCompleteResultToken" style="font-weight:400">mike</span>
<span data-automation-id="searchInputAutoCompleteResultToken" style="font-weight:400">diana</span>
</span>
</span>
</li>
我将用户全名分为spans
,因此我想构建xpath,它将从单个list
返回两个/多个span的组合文本
目前,我正在使用2个或更多的xpath,基于用户名称划分为span
我使用://li[.//span[text()='mike']]
//li[.//span[text()='diana']]
然后我使用java语法对上述xpath和merge进行gettext()
。因此,我正在寻找一种解决方案,它可以为我提供上面特定li
标记中所有span
的全文
# 1 楼答案
尝试以下XPath以其中一个跨度匹配元素:
或通过两个跨度:
# 2 楼答案
要在单行中获取特定li标记中所有跨度的全文,可以使用以下代码块: