Selenium: Select 间接兄弟元素

Selenium: Select indirect sibling element

我有以下 HTML 结构:

<div class="UFICommentContentBlock">
    <div class="UFICommentContent">
    <span>
    <span>
        <span data-ft="{"tn":"K"}">
            <span class="UFICommentBody">
                <span>My comment text</span>
            </span>
        </span>
    </span>
    <div class="UFITranslatedText"></div>
    <span></span>
</div>
<div class="fsm fwn fcg UFICommentActions">
    <a class="UFILikeLink" data-ft="{"tn":">"}" data-testid="ufi_comment_like_link" href="#" role="button" title="Like this comment">Like</a>
    <span role="presentation" aria-hidden="true"> · </span>
    <a class="UFIReplyLink" href="#" role="button">Reply</a>
    <span role="presentation" aria-hidden="true"> · </span>
    <span>
</div>
<a class="UFICommentCloseButton _5upq _5upr _5upp _42ft" data-testid="ufi_comment_close_button" data-hover="tooltip" data-tooltip-alignh="center" data-tooltip-content="Edit or delete this" href="#" id="js_c">   </a>
</div>  

这里是Facebook评论区。 我在 post 下面有几个评论,每个都是相同的结构。 我可以通过

找到所需的评论
xpath("//div[@class='UFICommentContentBlock']//span[@class='UFICommentBody']//span[text()='My comment text']")  

我需要访问此评论的“编辑评论”按钮,该评论也是 UFICommentContentBlock 的子元素,但不是包含评论文本的元素的直接同级元素,因此

xpath("//div[@class='UFICommentContentBlock']//span[@class='UFICommentBody']//span[text()='.']/following-sibling::div[@class='fsm fwn fcg UFICommentActions']/a[@class='UFICommentCloseButton _5upq _5upr _5upp _42ft']")  

不起作用。
需要你的帮助 select 它

使用这个:-

//span[text()='My comment text']/ancestor::div[@class='UFICommentContentBlock']//a[contains(@class,'UFICommentCloseButton')]

//span[text()=.]/ancestor::div[@class='UFICommentContentBlock']//a[contains(@class,'UFICommentCloseButton')]

ID 也提到了 a 标签。所以你也可以使用 id:-

//span[text()=.]/ancestor::div[@class='UFICommentContentBlock']//a[@id='js_c']

//a[@id='js_c']