1

On my web application I am attempting to select a button within a cell in a table.

Not every cell will contain a show details button and the button is only displayed depending on the text within that cell

Screenshot below

enter image description here

<td>
    Allocated
    <button ng-show="row.entitlementId" id="btnShowDetails" class="btn btn-primary btn-sm" style="width: 110px; float:right;" ng-click="showAllocationMonetaryDetails(row.entitlementId, CisBusinessID);" title="Show Details">
         <span class="glyphicon glyphicon-search"></span>Show Details
    </button>
    <br>
    <div style="font-size: small; color: darkgreen" ng-show="row.manualEstablishCommandType >= 0">
         Adjustment
    </div>
    <div style="font-size: small; color: darkgreen" ng-show="row.manualReclaimCommandType >= 0">

    </div>
</td>

I attempted to use the following xpath to locate the show details button but it does not work.

("//td[contains(.,'Allocated') and (contains(@id,'btnShowDetails'))]")

Does anybody know how I can select the Show Details button?

Thanks

Andersson
  • 51,635
  • 17
  • 77
  • 129
AlpineF30
  • 95
  • 2
  • 7
  • have a look here: https://stackoverflow.com/questions/21350605/python-selenium-click-on-button/37279279#37279279 – Carlo 1585 Sep 03 '18 at 13:44

2 Answers2

2

@id='btnShowDetails' is not an attribute of td, but attribute of child button

Try below XPath to select required element:

//td[starts-with(normalize-space(),'Allocated') and button[@id='btnShowDetails']]

or

//td[normalize-space(text())='Allocated' and button[@id='btnShowDetails']]
Andersson
  • 51,635
  • 17
  • 77
  • 129
  • Thank you :) That has enabled me to select the cell which contains the button but whenever I use this xpath it does not isolate and select the button – AlpineF30 Sep 03 '18 at 14:02
  • If you want to select the button: `//td[normalize-space(text())='Allocated']/button[@id='btnShowDetails']` – Andersson Sep 03 '18 at 14:05
2

In your cell td there is no id attribute its under the button you can modify your xpath like this:

//td[contains(.,'Allocated') and (contains(button/@id,'btnShowDetails'))]
Amrendra Kumar
  • 1,806
  • 1
  • 7
  • 17