Java 如何从不同级别的div定义xpath

Java 如何从不同级别的div定义xpath,java,html,selenium-webdriver,Java,Html,Selenium Webdriver,在下面的HTML中,我想将xpath定义为一个,但对象标识符位于不同的div级别 以蓝色和黄色突出显示的div的屏幕截图 实际HTML如下: <div class="option mli-body-1 selected ng-star-inserted" tabindex="0" ng-reflect-klass="option mli-body-1" ng-reflect-ng-class="[object Object]"> <mat-checkbox class

在下面的
HTML
中,我想将
xpath
定义为一个,但对象标识符位于不同的div级别

以蓝色和黄色突出显示的div的屏幕截图

实际HTML如下:

<div class="option mli-body-1 selected ng-star-inserted" tabindex="0" ng-reflect-klass="option mli-body-1" ng-reflect-ng-class="[object Object]">
    <mat-checkbox class="mat-checkbox mat-accent mat-checkbox-checked" ng-reflect-checked="true" id="mat-checkbox-97">
        <label class="mat-checkbox-layout" for="mat-checkbox-97-input">
            <div class="mat-checkbox-inner-container">
                <input class="mat-checkbox-input cdk-visually-hidden" type="checkbox" id="mat-checkbox-97-input" tabindex="0" aria-label="" aria-checked="true">
                <div class="mat-checkbox-ripple mat-ripple" matripple="" ng-reflect-centered="true" ng-reflect-radius="25" ng-reflect-animation="[object Object]" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLLabelElement]"></div>
                <div class="mat-checkbox-frame"></div>
                <div class="mat-checkbox-background">
                    <svg xml:space="preserve" class="mat-checkbox-checkmark" focusable="false" version="1.1" viewBox="0 0 24 24">
                        <path class="mat-checkbox-checkmark-path" d="M4.1,12.7 9,17.6 20.3,6.3" fill="none" stroke="white"></path>
                    </svg>
                    <div class="mat-checkbox-mixedmark"></div>
                </div>
            </div>
            <span class="mat-checkbox-label">
                <span style="display:none">&nbsp;</span>
                <mli-selected-text ng-reflect-text="Inforce (3)" ng-reflect-highlighted="">
                    <span>Inforce (3)</span>
                </mli-selected-text>
            </span>
        </label>
    </mat-checkbox>
</div>

使用以下XPath:

//input[@aria-checked='true']//parent::node()//following-sibling ::span//span[contains(text(),'Inforce')]

你能提供实际的html代码而不是图像吗?你能提供实际的html代码来代替图像吗?嗨,Pritam,我已经更新了帖子,包括实际的html,谢谢!这很有效,非常感谢。我试了一天,你在不到一分钟内就解决了。非常感谢。你现在可以投票表决我的答案了吗?它们对我定义的xpath也起作用,因为我有4个级别的Div,我选中了aria,因为它表明选中了复选框,但是,当我试图将span文本更改为“Expired”时,aria选中的是false,它仍然被发现,这是不应该的
//input[@aria-checked='true']//parent::node()//following-sibling ::span//span[contains(text(),'Inforce')]