java - Handling multiple tables using selenium webdriver -


i checking folder hierarchy on webpage, depending on type of user. user1 has set of permissions enable him see folder structure :

main folder     - first child         -first grandchild         -second grandchild     - second child     - third child 

each branch of tree table consisting of 1 row. number of columns varies depending on generation.

the "main folder" parent has 1 column. cell content string "main folder".

the children branches have 2 columns, first cell containing blank space, , next cell containing name of branch ("first child", "second child").

the grandchildren branches have 3 columns, first , second cell containing blank space, , the third cell containing name of branch (" first grandchild", "second grandchild").

html code :

<div id = 0>     <div id = 1>     <table id = 1>     <tbody>         <tr>             <td id="content1"                  <a id="label1"                  <span id="treenode1"                   main folder                 </span>                 </a>            </td>        </tr>     </tbody>     </table>              <div id = 2>             <table id = 2>             <tbody>                  <tr>                     <td>                         <td id="content2"                          <a id="label2"                          <span id="treenode2"                               first child                          </span>                         </a>                     </td>                     </td>                  </tr>            </tbody>            </table>                      <div id = 5>                     <table id = 5>                     <tbody>                          <tr>                             <td>                             <td>                             <td id="content5"                                  <a id="label5"                                  <span id="treenode5"                                       first grandchild                                  </span>                                 </a>                             </td>                             </td>                             </td>                          </tr>                   </tbody>                   </table>                   </div>                      <div id = 6>                     <table id = 6>                     <tbody>                          <tr>                             <td>                             <td>                             <td id="content6"                                  <a id="label6"                                  <span id="treenode6"                                       second grandchild                                  </span>                                 </a>                             </td>                             </td>                             </td>                        </tr>                 </tbody>                 </table>                 </div>             </div> /* end of division 2 */               <div id = 3>             <table id = 3>             <tbody>                  <tr>                         <td>                         <td id="content3"                              <a id="label3"                              <span id="treenode3"                                   second child                              </span>                             </a>                        </td>                        </td>                 </tr>             </tbody>             </table>             </div>               <div id = 4>             <table id = 4>             <tbody>             <tr>                         <td>                         <td id="content4"                              <a id="label4"                              <span id="treenode4"                                   third child                              </span>                             </a>                         </td>                         </td>             </tr>           </tbody>           </table>           </div>      </div> /*end of division 1 */ </div> /* end of division 0 */ 

user2 has different set of permissions, enable him see folder structure :

main folder     - first child         -first grandchild     - second child     - third child 

the corresponding table absent in html code user.

my test case check user2 doesn't have access second grandchild. means need ensure particular table doesn't exist on webpage.

how can check in selenium ? using junit test cases. want "assert" ensure second grandchild not present.

you'll want check see if element not present or not visible. calling iselementvisible() inside assert false should trick. locator of elements want check.

private boolean iselementvisible(by by) {     try     {         return driver.findelement(by).isdisplayed();     }     catch(nosuchelementexception e)     {         return false;     } } 

Comments