Select checkbox within table-row by name

32 views
Skip to first unread message

Fabio Rafaelli

unread,
Jul 6, 2020, 4:26:33 PM7/6/20
to Selenium Users
Dear all,
i have a table with products name.
Give a product i can select the next one with the instruction : driver.findElement(By.xpath("//sb-table-row[@name='"+Product+"']/following::paper-checkbox[1]")).click();
The problem is that i want the checkbox of the given product.
I've tried driver.findElement(By.xpath("//sb-table-row[@name='"+Product+"']/../following::paper-checkbox[1]")).click(); but i receive no element found error.
This is the full xpath related to the checkbox :
/html/body/sb-page-container/div/sb-product-lookup/paper-drawer-panel/iron-selector/div[1]/div[1]/sb-lookup-layout/div/div[2]/iron-list/div/sb-table-row[2]/sb-swipe-container/div/div[1]/sb-group/div/div/sb-table-cell-select/div/paper-checkbox
I do not want to use a long xpath because i have several environments and a notation like //sb-table-row[@name='"+Product+"']/following::paper-checkbox[1] is more robust.
Thanks to all for the collaboration
Fabio

Ankit Mundra

unread,
Jul 7, 2020, 12:59:17 AM7/7/20
to Selenium Users
Hi Fabio

Going by what you have said. I think the xpath you have created is not correct to get the checkbox for the current product. I would suggest that you refer the
Xpath Axes. In your case the preceding and preceding-sibling might work. Since your dom is not present this is the best we can help you with.

Fabio Rafaelli

unread,
Jul 7, 2020, 1:52:11 AM7/7/20
to Selenium Users
Hi all,
below the dom of the table-row.
Thanks again for your help.
BR
Fabio

<sb-table-row disable-swipe="true" id="tableRow" cell="sb-table-cell" selectable="true" repeat-primary-mobile-cols="true" route-source="LookupLayout" row-actions="[]" defer-grouping="true" no-data-propagation="true" class="style-scope sb-lookup-layout --desktop x-scope sb-table-row-0" name="localBUSINESS Starter" index="2" style="transform: translate3d(0px, 97px, 0px);">     <sb-swipe-container device="" class="style-scope sb-table-row --desktop x-scope sb-swipe-container-0" style="min-width: 100%; position: static;">   <div id="swipe-header" class="style-scope sb-table-row"> <div id="selectionContainer" class="style-scope sb-table-row td"> <sb-group id="selection" item="sb-table-cell-select" class="style-scope sb-table-row --desktop innerTd selection x-scope sb-group-0">   <div id="g" device="" class="style-scope sb-group --desktop"><div class="style-scope sb-group"><sb-table-cell-select item="checkbox" index="0" class="--desktop style-scope sb-group x-scope sb-table-cell-select-0"> <div id="s" class="style-scope sb-table-cell-select"> <template is="dom-if" class="style-scope sb-table-cell-select"></template>  <paper-checkbox device="" noink="" id="checkbox" class="style-scope sb-table-cell-select x-scope paper-checkbox-0" role="checkbox" tabindex="0" toggles="" aria-checked="false" aria-disabled="false"><div id="checkboxContainer" class="style-scope paper-checkbox"><div id="checkbox" class="style-scope paper-checkbox"><div id="checkmark" class="hidden style-scope paper-checkbox"></div></div></div><div id="checkboxLabel" class="style-scope paper-checkbox"></div></paper-checkbox> <template is="dom-if" class="style-scope sb-table-cell-select"></template> </div> </sb-table-cell-select></div><template is="dom-bind" tabindex="-1" class="style-scope sb-group"><div><sb-table-cell-select item="checkbox" index="0"></sb-table-cell-select></div></template></div> </sb-group> <paper-tooltip for="selection" animation-delay="250" offset="5" fit-to-visible-bounds="true" class="style-scope sb-table-row x-scope paper-tooltip-0" role="tooltip" tabindex="-1">  <div id="tooltip" class="hidden style-scope paper-tooltip">  <template is="dom-repeat" as="messageLine" class="style-scope sb-table-row"></template>  </div> </paper-tooltip> </div>  <template is="dom-if" class="style-scope sb-table-row"></template> <template is="dom-if" class="style-scope sb-table-row"></template> <div id="rowDiv" class="td style-scope sb-table-row"> <sb-group id="row" group-class="tgroup" item-class="innerTd" class="style-scope sb-table-row --desktop x-scope sb-group-0">   <div id="g" device="" class="style-scope sb-group --desktop"><div class="tgroup style-scope sb-group"><sb-table-cell item="Product2.Name" index="0" class="innerTd primary first firstInnerTd style-scope sb-group">  <div class="container style-scope sb-table-cell"> <sb-field id="field" class="style-scope sb-table-cell --desktop x-scope sb-field-1">  <span device="" class="style-scope sb-field --desktop"> <div id="f" class="style-scope sb-field"></div> <div id="formatted" class="style-scope sb-field readOnly" style="padding: 2px 0px;"> <span id="me" class="style-scope sb-field">localBUSINESS Starter</span> </div> </span> </sb-field> </div> </sb-table-cell><sb-table-cell item="Product2.Configuration_Model__c" index="1" class="innerTd primary multi secondInnerTd style-scope sb-group">  <div class="container style-scope sb-table-cell"> <sb-field id="field" class="style-scope sb-table-cell --desktop x-scope sb-field-1">  <span device="" class="style-scope sb-field --desktop"> <div id="f" class="style-scope sb-field"></div> <div id="formatted" class="style-scope sb-field readOnly" style="padding: 2px 0px;"> <span id="me" class="style-scope sb-field">Fixed Term</span> </div> </span> </sb-field> </div> </sb-table-cell><sb-table-cell item="Product2.Family" index="2" field-label="Product Family" class="innerTd secondary style-scope sb-group">  <div class="container style-scope sb-table-cell"> <sb-field id="field" class="style-scope sb-table-cell --desktop x-scope sb-field-1">  <span device="" class="style-scope sb-field --desktop"> <div id="f" class="style-scope sb-field"></div> <div id="formatted" class="style-scope sb-field readOnly" style="padding: 2px 0px;"> <span id="me" class="style-scope sb-field">Presence</span> </div> </span> </sb-field> </div> </sb-table-cell><sb-table-cell item="Product2.Description" index="3" field-label="Product Description" class="innerTd secondary style-scope sb-group">  <div class="container style-scope sb-table-cell"> <sb-field id="field" class="style-scope sb-table-cell --desktop x-scope sb-field-1">  <span device="" class="style-scope sb-field --desktop"> <div id="f" class="style-scope sb-field"></div> <div id="formatted" class="style-scope sb-field readOnly" style="padding: 2px 0px;"> <span id="me" class="style-scope sb-field">localBUSINESS Starter product with Fixed Term Configuration Model</span> </div> </span> </sb-field> </div> </sb-table-cell><sb-table-cell item="Product2.Base_term_Renewal_term__c" index="4" field-label="Base term / Renewal term" class="innerTd secondary style-scope sb-group">  <div class="container style-scope sb-table-cell"> <sb-field id="field" class="style-scope sb-table-cell --desktop x-scope sb-field-1">  <span device="" class="style-scope sb-field --desktop"> <div id="f" class="style-scope sb-field"></div> <div id="formatted" class="style-scope sb-field readOnly" style="padding: 2px 0px;"> <span id="me" class="style-scope sb-field">12</span> </div> </span> </sb-field> </div> </sb-table-cell><sb-table-cell item="Product2.Price_Not_Available__c" index="5" field-label="Pricing Information" class="innerTd secondary style-scope sb-group">  <div class="container style-scope sb-table-cell"> <sb-field id="field" class="style-scope sb-table-cell --desktop x-scope sb-field-1">  <span device="" class="style-scope sb-field --desktop"> <div id="f" class="style-scope sb-field"></div> <div id="formatted" class="style-scope sb-field"> <span id="me" class="style-scope sb-field"></span> </div> </span> </sb-field> </div> </sb-table-cell><sb-table-cell item="UnitPrice" index="6" field-label="List Price" class="innerTd secondary numericCell lastInnerTd style-scope sb-group">  <div class="container style-scope sb-table-cell"> <sb-field id="field" class="style-scope sb-table-cell --desktop x-scope sb-field-1">  <span device="" class="style-scope sb-field --desktop"> <div id="f" class="style-scope sb-field"></div> <div id="formatted" class="style-scope sb-field numericField readOnly" style="padding: 2px 0px;"> <span id="me" class="style-scope sb-field">590,00 CHF</span> </div> </span> </sb-field> </div> </sb-table-cell></div><template is="dom-bind" tabindex="-1" class="style-scope sb-group"><div class="tgroup"><sb-table-cell item="Product2.Name" index="0" class="innerTd primary first firstInnerTd"></sb-table-cell><sb-table-cell item="Product2.Configuration_Model__c" index="1" class="innerTd primary multi secondInnerTd"></sb-table-cell><sb-table-cell item="Product2.Family" index="2" field-label="Product Family" class="innerTd secondary"></sb-table-cell><sb-table-cell item="Product2.Description" index="3" field-label="Product Description" class="innerTd secondary"></sb-table-cell><sb-table-cell item="Product2.Base_term_Renewal_term__c" index="4" field-label="Base term / Renewal term" class="innerTd secondary"></sb-table-cell><sb-table-cell item="Product2.Price_Not_Available__c" index="5" field-label="Pricing Information" class="innerTd secondary"></sb-table-cell><sb-table-cell item="UnitPrice" index="6" field-label="List Price" class="innerTd secondary numericCell lastInnerTd"></sb-table-cell></div></template></div> </sb-group> </div>  <template is="dom-if" class="style-scope sb-table-row"></template> <template is="dom-if" class="style-scope sb-table-row"></template> <template is="dom-if" class="style-scope sb-table-row"></template> <template is="dom-if" class="style-scope sb-table-row"></template> </div> <template is="dom-if" class="style-scope sb-table-row"></template>  </sb-swipe-container> </sb-table-row>

Ankit Mundra

unread,
Jul 8, 2020, 12:40:53 AM7/8/20
to Selenium Users
Hi Fabio

Below is a sample xpath that should help you ::

//span[.="localBUSINESS Starter"]/preceding::div[@id='checkbox']/div

This should workout in your case. assuming that the very first preceding checkbox you get is that for the product.

Regards
Ankit M
Reply all
Reply to author
Forward
0 new messages