1

With Python Selenium, I want to click on a button "Add..." based on another div.

I cannot use the xpath following::div as spotted here because they are in different divs.

Basically, look for the first div text to contain some text and based on it, I want to click on button "Add..." on fourth div. This on a serie of Divs, as you can see on screenshot.

screenshoot

On example/code below, I want to find "Template 1" <- xpath //*[@id="app"]/div/div[3]/div/div[24]/div[1]/div/h3/text()[1]

and base on that

I want to click on button 'Add...' <- 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>
4
  • ok can you say few things? like the first div class is different or same with other divs? is there any specific id for the add buttons or all add buttons are smae? Commented May 15, 2017 at 6:38
  • There is several div class before - as you can see in the added xpath. The list of div which interest here start at //*[@id="app"]/div/div[3]/div/div[4]. The button are all the same, no id. Commented May 15, 2017 at 6:50
  • based on a text of another DIV... Which div? What is the text? Commented May 15, 2017 at 7:16
  • I added an example. The text change. Commented May 15, 2017 at 7:22

1 Answer 1

1

Try Below xpath and let me know if it is working for you

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

Explanation :

.//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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.