jeudi 19 septembre 2019

How to locate elements within elements with page-object-model?

Trying to get an List of WebElement type, in which each element is a List of WebElements.

Sample HTML:

  <div class="widget_column">
  <div class="g-cell">
    <div id="w_0" class="Widget Table_card">
      <div class="container">
        <div class="canvas">
          <table class="TblCard fixed">
            <tbody>
              <tr title="filter_1"/>
              <tr title="filter_2"/>
              <tr title="filter_3"/>
              <tr title="filter_4"/>
              <tr title="filter_5"/>
            </tbody>
          </table>
        </div>
        <div class="error_list"></div>
      </div>
    </div>
  </div>
  <div class="widget_column">
  <div class="g-cell">
    <div id="w_1" class="Widget Table_card">
      <div class="container">
        <div class="canvas">
          <table class="TblCard fixed">
            <tbody>
              <tr title="filter_1"/>
              <tr title="filter_2"/>
              <tr title="filter_3"/>
              <tr title="filter_4"/>
              <tr title="filter_5"/>
            </tbody>
          </table>
        </div>
        <div class="error_list"></div>
      </div>
    </div>
  </div>

The page has multiple widgets and each widget will have same set of filters

What I have tried:

  1. @FindBy(xpath = "//*[@class='widget_column'][*]//tr") private List<WebElement> widgets;

This give all the filters for each widget in a single list.

  1. @FindBy(xpath = "//*[@class='widget_column']") private List<WebElement> widgets;

This gives the list of widgets. Using which I can iterate though each element to get list of filters for each widget.

  1. Create locators for each widget and get the list of applied filters.

What I want:

Is there some way with page-object-model to use @FindBy/Bys/All, to get a list in which each element is a list of WebElements? Something like List<List<WebElement>>.

Aucun commentaire:

Enregistrer un commentaire