2016-04-12 17 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のコメントエリアです。 私はポストの下にいくつかのコメントがあり、それぞれは同じ構造です。 は、私はまた、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']") 
を含む要素の直接の兄弟であるこのコメントの編集コメントボタンに到達するために必要

xpath("//div[@class='UFICommentContentBlock']//span[@class='UFICommentBody']//span[text()='My comment text']") 

によって必要なコメントを見つけることができます

は機能しません。

答えて

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')] 

IDaタグに記載されています。だから、あなたにもIDを使用することができます -

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

OR

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

YESを! これは動作します! ありがとうございます!!!!!! – Eliyahu

関連する問題