2017-05-15 4 views
0

Python Seleniumでは、別のdivに基づいて "Add ..."ボタンをクリックします。Python Selenium - 別のDIVのテキストに基づいてdiv内のボタンをクリックする方法

xpath following::divは、別のdivにあるので、hereが見つかりませんでした。

基本的には、テキストを含む最初のdivテキストを探し、それに基づいて、4番目のdivの[Add ...]ボタンをクリックします。あなたがスクリーンショットで見ることができるように、Divsのセリフでこれは。

以下の例/​​コードに

screenshoot

、私は "テンプレート1" を見つけたい< - XPathのこと

//*[@id="app"]/div/div[3]/div/div[24]/div[1]/div/h3/text()[1]

とベース私は追加]ボタンをクリックします... 「< - XPathの//*[@id="app"]/div/div[3]/div/div[24]/div[4]/div/table/thead/tr/th[3]/button

<div style="margin-bottom: 50px;" class=""> 
    <div> 
     <div> 
     <h3> 
      <!-- react-text: 1148 -->Template 1<!-- /react-text --><!-- react-text: 1149 -->&nbsp;<!-- /react-text --> 
     </h3> 
     </div> 
    </div> 
    <div class="btn-group btn-table-action pull-right" style="vertical-align: top; top: -32px;"><button type="button" class="btn btn-link"><i class="fa fa-pencil-square-o" style="color: rgb(51, 122, 183);"></i></button><button type="button" class="btn btn-link"><i class="fa fa-trash-o" style="color: rgb(217, 83, 79);"></i></button></div> 
    <div class="detail-pane" style="background-color: rgb(245, 245, 245); border-radius: 4px; font-size: 90%; padding: 4px 20px; margin-bottom: 14px;"> 
     <div> 
     <h5></h5> 
     <dl class="dl-horizontal"> 
      <span> 
       <dt style="font-weight: normal;">Key</dt> 
       <dd style="font-weight: normal;">template-1-key</dd> 
      </span> 
     </dl> 
     </div> 
    </div> 
    <div> 
     <h5 style="color: rgb(95, 94, 94); margin-top: 27px;">Templates</h5> 
     <div class="detail-pane" style="background-color: rgb(245, 245, 245); border-radius: 4px; font-size: 90%; padding: 4px 20px; margin-bottom: 14px;"> 
     <table class="table table-hover" style="table-layout: fixed;"> 
      <thead> 
       <tr> 
        <th>Language</th> 
        <th>Asset Path</th> 
        <th> 
        <button type="button" class="btn btn-primary pull-right btn-xs" style="margin-left: 6px;"> 
         <span> 
          <i class="fa fa-plus-square-o">&nbsp;</i><!-- react-text: 1174 -->Add...<!-- /react-text --> 
         </span> 
        </button> 
        </th> 
       </tr> 
      </thead> 
      <tbody> 
       <tr> 
        <td colspan="3">No entries found so far...</td> 
       </tr> 
      </tbody> 
     </table> 
     </div> 
    </div> 
</div> 
+0

OKあなたはいくつかのことを言うことができますか?最初のdivクラスのように他のdivと違うか同じですか?追加ボタンの特定のIDがあるか、すべての追加ボタンがsmaeですか? – Exprator

+0

追加されたxpathには、いくつかのdivクラスがあります。ここで関心のあるdivのリストは、// // [@ id = "app"]/div/div [3]/div/div [4] 'で始まります。ボタンはすべて同じで、IDはありません。 – cgasp

+0

*別のDIVのテキストに基づいて* ...どちらのdiv?テキストは何ですか? – Andersson

答えて

0

は、XPathの下には試してみて、それがFOを働いているなら、私に知らせてRあなたは説明

.//div/h3[text()[normalize-space() = 'Template 1']]/../../following-sibling::div/div//table//tr/th/button[@type='button'] 

.//div/h3[text()[normalize-space() = 'Template 1']] // To locate element with "Template 1" text 

/../..  // to navigate the parent node for template 1 node 

following-sibling::div/div//table//tr/th/button[@type='button'] // Locate the button node which is sibling node of parent div of Template 1 text 
関連する問題