Select child of List WebElement - Java - Selenium WebDriver -


i have table need say, if row contains text click cells on row.

i trying create list of rows, iterate through columns of each row , if text found in row, click cell deselect item following (which doesn't work, trying figure out logic).

// deselect pending quality review list<webelement> parents = driver.findelements(by.cssselector("tr[type='row']")); for(webelement parent : parents)  {     list<webelement> children = parent.findelements(by.cssselector("td[class='grdcell']"));     for(webelement child : children)     {         if (parent.gettext().contains("pending quality review") && child.getattribute("style").contains("visible"))         {             system.out.println("deselect pending quality review");             child.click();         } //end if     } // end child loop } // end parent element 

here example html of i'm working with. first row has 2 selection boxes while second row has 1 indicated img tag.

<tr type="row" adr="14" tag="" id="x:1011327536.13:adr:14:tag:">     <td type="cell" adr="0" idx="0" class="grdcell">cancelled</td>     <td class="ig9a63765d">1</td>     <td class="ig9a63765e">1</td>     <td type="cell" adr="3" idx="3" class="grdcell">         <img id="ctl00_ctl00_ctl00_main_main_main_gridstatussyncmappings_it3_14_imgsync" src="images/bluearrowleft32x32.png" alt="" style="visibility:visible;"></td>     <td class="ig9a63765f">1</td>     <td class="ig9a637660">1</td>     <td class="grdcell">         <img id="ctl00_ctl00_ctl00_main_main_main_gridstatussyncmappings_it6_14_imgsync" src="images/bluearrowright32x32.png" alt="" style="visibility:visible;"></td>     <td type="cell" adr="7" idx="7" class="grdcell">cancelled</td>     <td class="ig9a637661">300020</td>     <td class="ig9a637662">1</td>     <td class="ig9a637663">1</td>     <td class="ig9a637664">1</td>     <td class="ig9a637665"></td>     <td class="ig9a637666">1</td>     <td class="ig9a637667"></td> </tr>  <tr type="row" adr="15" tag="" id="x:1011327536.13:adr:15:tag:" class="ig_listalt igg_listalt ">     <td type="cell" adr="0" idx="0" class="grdcell">pending quality review</td>     <td class="ig9a63765d">1</td>     <td wlkd="1" type="cell" idx="2" adr="2" class="ig9a63765e">1</td>     <td wlkd="1" type="cell" adr="3" idx="3" class="grdcell">         <img id="ctl00_ctl00_ctl00_main_main_main_gridstatussyncmappings_it3_15_imgsync" src="images/bluearrowleft32x32.png" alt="" style="visibility: visible;">        </td>     <td class="ig9a63765f">0</td>     <td class="ig9a637660">0</td>     <td type="cell" adr="6" idx="6" class="grdcell grdcell_cursordefault grdcell_gray grdcell"></td>     <td type="cell" adr="7" idx="7" class="grdcell">pending quality review</td>     <td class="ig9a637661">301002</td>     <td wlkd="1" type="cell" idx="9" adr="9" class="ig9a637662">1</td>     <td class="ig9a637663">0</td>     <td class="ig9a637664">1</td>     <td class="ig9a637665"></td>     <td class="ig9a637666">1</td>     <td class="ig9a637667"></td> </tr> 

so in example, i'm need select pending quality review row , if img of cell contains visible, click it.

in future, may need along lines of saying if row cancelled, select 2nd option. details on how helpful well.

if (parent.gettext().contains("pending quality review") && ***child.getattribute("style").contains("visible")***) 

the child webelement td , not contain style 'visibilty: visible' nothing getting clicked.

list<webelement> children = parent.findelements(by.cssselector("***td[class='grdcell']***")); 

you have go down img level attribute.

plus can confirm parent.gettext.contains part, work correctly? knowledge guessing trying consolidated text in child tds , search text.

an alternate approach using locators... copy pasted code come following table borders added. correct cause based locators on table. (somehow unable attach image, put down link)

http://i.stack.imgur.com/mdxcp.png

for selecting rows 'pending quality review' text can use following locator gather images visible --

"//td[@class='grdcell'][text()='pending quality review'][1]/following-sibling::td[3]/img[contains(@style,'visible')]" 

this give list of images can click.

for selecting rows cancelled text , click on 2nd image when visible ---

"//td[@class='grdcell'][text()='cancelled'][1]/following-sibling::td[6]/img[contains(@style,'visible')]" 

one of pitfalls approach fail if table restructured shifting columns. if add unique classes img tags numbers can removed second td.


Comments