三种场景下页面活跃奖金计划的XPATH定位问题求助
筛选未被移除的活跃奖金计划(XPath解决方案)
我需要从页面中定位所有未被移除的活跃奖金计划,但页面存在三种不同的HTML结构场景,导致无法写出正确的XPath:
场景1:无Modified/Added标记的活跃计划
这类活跃计划没有任何状态标记元素,HTML结构如下:
<div data-automation-id="decorationWrapper" id="56$742835" class="WBUI"> <div class="WMRI"> <div class="wd-Text WGI0 WNI0 WC5" data-automation-id="textView">STI FY26 Non-standard Incentive - AMS APJ Temporary Employees </div> </div> </div>
场景2:含Removed标记的已移除计划
这类是已失效/移除的计划,页面中存在(empty)文本的div和Removed标记的span,HTML结构如下:
<div data-automation-id="decorationWrapper" id="56$742835" class="WBUI"> <div class="WMRI"> <div data-automation-id="textView"> <div data-automation-id="wd-NoValuePresentPlaceholder" id="wd-NoValuePlaceholder-56$742835">(empty)</div> </div> </div> <div> <div data-metadata-id="NO_METADATA_ID"> <div data-automation-id="deltaviewContainer"> <span type="red" data-automation-id="deltaviewLabel"><span class="css-1ynlkts">Removed</span></span> <div data-automation-id="deltaviewValueContainer"><label data-automation-id="deltaviewValue" ><del data-automation-id="deltaviewTextValue">STI FY26 Sales Incentive Plan</del></label></div> </div> </div> </div> </div>
场景3:含Added/Modified标记的活跃计划
这类活跃计划带有Added或Modified状态标记,且无Removed或(empty)文本,HTML结构如下:
<div data-automation-id="decorationWrapper"> <div class="WMRI"> <div data-automation-id="textView">STI FY26 PfR HPE</div> </div> <div> <div data-metadata-id="NO_METADATA_ID"> <div data-automation-id="deltaviewContainer"> <span type="blue" data-automation-id="deltaviewLabel"><span class="css-1ynlkts">Added</span></span> <div data-automation-id="deltaviewValueContainer"> <label data-automation-id="deltaviewValue" > <div data-automation-id="deltaviewTextValue"></div> </label> </div> </div> </div> </div> </div>
尝试过的无效XPath
我之前尝试了以下XPath,但都无法正确筛选:
//div[@data-automation-id='decorationWrapper']//not(.//div[@data-automation-id='deltaviewContainer']/span/span[text()='Removed']) //div[@data-automation-id='decorationWrapper']//div[not(.//div[@data-automation-id='wd-NoValuePresentPlaceholder'])] //span[@data-automation-id='deltaviewLabel']/span[text()='Added' or text()='Modified']
正确的XPath表达式
以下XPath可以精准选中所有活跃计划,排除已移除的:
//div[@data-automation-id='decorationWrapper'][not(.//span[text()='Removed']) and not(.//div[text()='(empty)'])]
表达式解释
//div[@data-automation-id='decorationWrapper']:定位所有计划的根容器[not(.//span[text()='Removed'])]:排除包含Removed标记的已移除计划[not(.//div[text()='(empty)'])]:排除包含(empty)文本的已移除计划
这个表达式同时覆盖了三种场景:
- 匹配场景1:无状态标记且无Removed/(empty)的活跃计划
- 排除场景2:含Removed/(empty)的已移除计划
- 匹配场景3:含Added/Modified且无Removed/(empty)的活跃计划
内容的提问来源于stack exchange,提问作者Nitin Rathod
相关产品推荐
相关产品推荐

