selenium - Clicking on checkbox based on span value in WebDriver -
i select checkbox based on "costco wholesale corporation" value in:
<td role="gridcell" style="" title="" aria-describedby="entity-search-grid_selected"> <input type="checkbox" name="chkbox" class="itmchk" value="110504"> </td> <td role="gridcell" style="font-weight: bold;" title="costco wholesale corporation" aria-describedby="entity-search-grid_name"> <div class="tree-wrap tree-wrap-ltr" style="width:18px;"> <div style="left:0px;" class="ui-icon ui-icon-triangle-1-s tree-minus treeclick"></div> </div> <span class="cell-wrapper">costco wholesale corporation</span> </td>
i have tried following code:
driver.findelement(by.xpath("//td[span[text()='costco wholesale corporation']]/preceding-sibling::td/input[@name='chkbox'"));
but getting following exception:
invalid selector: unable locate element xpath expression //td[span[text()='costco wholesale corporation']]/preceding-sibling::td/input[@name='chkbox' because of following error: syntaxerror: failed execute 'evaluate' on 'document': string '//td[span[text()='costco wholesale corporation']]/preceding-sibling::td/input[@name='chkbox''
could write xpath selector.
your first problem xpath td[span[text()
invalid. remember [...]
syntax filters, not defining path. has be:
//td/span[text...
also since select span
first, need td
level , choose sibling:
//td/span[text()='costco wholesale corporation']/../preceding-sibling::td/input[@name='chkbox']
given html, simplify select td
byt title , sibling:
//td[@title='costco wholesale corporation']/preceding-sibling::td/input[@name='chkbox']
Comments
Post a Comment