2016-04-12 28 views
0

我有以下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的留言區域。 我在帖子下面有幾條評論,每條都有相同的結構。 我可以找到

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']") 
直接同級的編輯評論按鈕所需的評論

不起作用。
需要你的幫助,將其選中

回答

1

使用此: -

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

OR

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

ID也提到a標籤。所以,你可以用ID,以及: -

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

OR

//a[@id='js_c'] 
+0

YES! 這個作品! 謝謝!!!!!! – Eliyahu