The list of table elements found by Xpath contains only visible ten elements with correct text values that...












-1
















  1. I want to get a List of WebElement objects from framable table and go through it getting texts using getText() method in case if number of elements is greater than 10. Only 10 columns are visible for user.


  2. My table is framed and shows only 10 columns at time, so findElements gets only these ten column names.



Code, that I used to get my column values:
Code:



public void getColumnsList() throws Exception{
List<WebElement> elements = driver.findElements(By.xpath(//*[contains(@id, 'window-')]//*[contains(@id, '-textContainerEl')]));
for (WebElement el:elements){
System.out.println(elements.indexOf(el)+" element "+el.getText());
}
}


Expected result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element Column11
11 element Column12
12 element Column13
13 element Column14
14 element Column15


Actual result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element
11 element
12 element
13 element
14 element









share|improve this question

























  • Welcome to Stack Overflow! It's not clear to me why you expect Column11 through Column15 in your output. Please edit your question to provide a Minimal, Complete, and Verifiable example (with focus on "Verifiable") that demonstrates your issues.

    – Joe C
    Jan 1 at 19:58
















-1
















  1. I want to get a List of WebElement objects from framable table and go through it getting texts using getText() method in case if number of elements is greater than 10. Only 10 columns are visible for user.


  2. My table is framed and shows only 10 columns at time, so findElements gets only these ten column names.



Code, that I used to get my column values:
Code:



public void getColumnsList() throws Exception{
List<WebElement> elements = driver.findElements(By.xpath(//*[contains(@id, 'window-')]//*[contains(@id, '-textContainerEl')]));
for (WebElement el:elements){
System.out.println(elements.indexOf(el)+" element "+el.getText());
}
}


Expected result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element Column11
11 element Column12
12 element Column13
13 element Column14
14 element Column15


Actual result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element
11 element
12 element
13 element
14 element









share|improve this question

























  • Welcome to Stack Overflow! It's not clear to me why you expect Column11 through Column15 in your output. Please edit your question to provide a Minimal, Complete, and Verifiable example (with focus on "Verifiable") that demonstrates your issues.

    – Joe C
    Jan 1 at 19:58














-1












-1








-1









  1. I want to get a List of WebElement objects from framable table and go through it getting texts using getText() method in case if number of elements is greater than 10. Only 10 columns are visible for user.


  2. My table is framed and shows only 10 columns at time, so findElements gets only these ten column names.



Code, that I used to get my column values:
Code:



public void getColumnsList() throws Exception{
List<WebElement> elements = driver.findElements(By.xpath(//*[contains(@id, 'window-')]//*[contains(@id, '-textContainerEl')]));
for (WebElement el:elements){
System.out.println(elements.indexOf(el)+" element "+el.getText());
}
}


Expected result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element Column11
11 element Column12
12 element Column13
13 element Column14
14 element Column15


Actual result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element
11 element
12 element
13 element
14 element









share|improve this question

















  1. I want to get a List of WebElement objects from framable table and go through it getting texts using getText() method in case if number of elements is greater than 10. Only 10 columns are visible for user.


  2. My table is framed and shows only 10 columns at time, so findElements gets only these ten column names.



Code, that I used to get my column values:
Code:



public void getColumnsList() throws Exception{
List<WebElement> elements = driver.findElements(By.xpath(//*[contains(@id, 'window-')]//*[contains(@id, '-textContainerEl')]));
for (WebElement el:elements){
System.out.println(elements.indexOf(el)+" element "+el.getText());
}
}


Expected result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element Column11
11 element Column12
12 element Column13
13 element Column14
14 element Column15


Actual result:



0 element Column1 
1 element Column2
2 element Column3
3 element Column4
4 element Column5
5 element Column6
6 element Column7
7 element Column8
8 element Column9
9 element Column10
10 element
11 element
12 element
13 element
14 element






java list selenium webdriver






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 4 at 20:09







Grigoriy Yuschenko

















asked Jan 1 at 19:50









Grigoriy YuschenkoGrigoriy Yuschenko

213




213













  • Welcome to Stack Overflow! It's not clear to me why you expect Column11 through Column15 in your output. Please edit your question to provide a Minimal, Complete, and Verifiable example (with focus on "Verifiable") that demonstrates your issues.

    – Joe C
    Jan 1 at 19:58



















  • Welcome to Stack Overflow! It's not clear to me why you expect Column11 through Column15 in your output. Please edit your question to provide a Minimal, Complete, and Verifiable example (with focus on "Verifiable") that demonstrates your issues.

    – Joe C
    Jan 1 at 19:58

















Welcome to Stack Overflow! It's not clear to me why you expect Column11 through Column15 in your output. Please edit your question to provide a Minimal, Complete, and Verifiable example (with focus on "Verifiable") that demonstrates your issues.

– Joe C
Jan 1 at 19:58





Welcome to Stack Overflow! It's not clear to me why you expect Column11 through Column15 in your output. Please edit your question to provide a Minimal, Complete, and Verifiable example (with focus on "Verifiable") that demonstrates your issues.

– Joe C
Jan 1 at 19:58












1 Answer
1






active

oldest

votes


















0














Because of driver.findElements always sees only visible part of my framable table it was required to get text values into separate lists directly, moving through all cells of the entire row (I was needed the first row cells also):



public TableElements getTableElements() throws Exception {
if (getColumnsList()!=null) {

List<WebElement> elements = getColumnsList();
List<String> columnNames = new ArrayList<>();
List<String> rowValues = new ArrayList<>();
ListIterator<WebElement> listItr = null;
int columnsNumber = elements.size();
System.out.println("columnsNumber is: " + columnsNumber + " in " + driver.findElement(By.xpath(datasource)).getText());
WebElement cell = driver.findElement(By.xpath(getValue("firstColumnXpath")));
cell.click();
listItr = elements.listIterator();
while (listItr.hasNext()) {
columnNames.add(listItr.next().getText());
rowValues.add(driver.switchTo().activeElement().getText());
driver.switchTo().activeElement().sendKeys(Keys.ARROW_RIGHT);
}
return new TableElements(columnNames, rowValues);
}
else {
return new TableElements(null, null);
}
}

public List<WebElement> getColumnsList() throws Exception {
if (CSSElementExists(getValue("columnLabelsCSS")))
return driver.findElements(By.xpath(getValue("columnLabelsXpath")));
return null;
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998459%2fthe-list-of-table-elements-found-by-xpath-contains-only-visible-ten-elements-wit%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Because of driver.findElements always sees only visible part of my framable table it was required to get text values into separate lists directly, moving through all cells of the entire row (I was needed the first row cells also):



    public TableElements getTableElements() throws Exception {
    if (getColumnsList()!=null) {

    List<WebElement> elements = getColumnsList();
    List<String> columnNames = new ArrayList<>();
    List<String> rowValues = new ArrayList<>();
    ListIterator<WebElement> listItr = null;
    int columnsNumber = elements.size();
    System.out.println("columnsNumber is: " + columnsNumber + " in " + driver.findElement(By.xpath(datasource)).getText());
    WebElement cell = driver.findElement(By.xpath(getValue("firstColumnXpath")));
    cell.click();
    listItr = elements.listIterator();
    while (listItr.hasNext()) {
    columnNames.add(listItr.next().getText());
    rowValues.add(driver.switchTo().activeElement().getText());
    driver.switchTo().activeElement().sendKeys(Keys.ARROW_RIGHT);
    }
    return new TableElements(columnNames, rowValues);
    }
    else {
    return new TableElements(null, null);
    }
    }

    public List<WebElement> getColumnsList() throws Exception {
    if (CSSElementExists(getValue("columnLabelsCSS")))
    return driver.findElements(By.xpath(getValue("columnLabelsXpath")));
    return null;
    }





    share|improve this answer






























      0














      Because of driver.findElements always sees only visible part of my framable table it was required to get text values into separate lists directly, moving through all cells of the entire row (I was needed the first row cells also):



      public TableElements getTableElements() throws Exception {
      if (getColumnsList()!=null) {

      List<WebElement> elements = getColumnsList();
      List<String> columnNames = new ArrayList<>();
      List<String> rowValues = new ArrayList<>();
      ListIterator<WebElement> listItr = null;
      int columnsNumber = elements.size();
      System.out.println("columnsNumber is: " + columnsNumber + " in " + driver.findElement(By.xpath(datasource)).getText());
      WebElement cell = driver.findElement(By.xpath(getValue("firstColumnXpath")));
      cell.click();
      listItr = elements.listIterator();
      while (listItr.hasNext()) {
      columnNames.add(listItr.next().getText());
      rowValues.add(driver.switchTo().activeElement().getText());
      driver.switchTo().activeElement().sendKeys(Keys.ARROW_RIGHT);
      }
      return new TableElements(columnNames, rowValues);
      }
      else {
      return new TableElements(null, null);
      }
      }

      public List<WebElement> getColumnsList() throws Exception {
      if (CSSElementExists(getValue("columnLabelsCSS")))
      return driver.findElements(By.xpath(getValue("columnLabelsXpath")));
      return null;
      }





      share|improve this answer




























        0












        0








        0







        Because of driver.findElements always sees only visible part of my framable table it was required to get text values into separate lists directly, moving through all cells of the entire row (I was needed the first row cells also):



        public TableElements getTableElements() throws Exception {
        if (getColumnsList()!=null) {

        List<WebElement> elements = getColumnsList();
        List<String> columnNames = new ArrayList<>();
        List<String> rowValues = new ArrayList<>();
        ListIterator<WebElement> listItr = null;
        int columnsNumber = elements.size();
        System.out.println("columnsNumber is: " + columnsNumber + " in " + driver.findElement(By.xpath(datasource)).getText());
        WebElement cell = driver.findElement(By.xpath(getValue("firstColumnXpath")));
        cell.click();
        listItr = elements.listIterator();
        while (listItr.hasNext()) {
        columnNames.add(listItr.next().getText());
        rowValues.add(driver.switchTo().activeElement().getText());
        driver.switchTo().activeElement().sendKeys(Keys.ARROW_RIGHT);
        }
        return new TableElements(columnNames, rowValues);
        }
        else {
        return new TableElements(null, null);
        }
        }

        public List<WebElement> getColumnsList() throws Exception {
        if (CSSElementExists(getValue("columnLabelsCSS")))
        return driver.findElements(By.xpath(getValue("columnLabelsXpath")));
        return null;
        }





        share|improve this answer















        Because of driver.findElements always sees only visible part of my framable table it was required to get text values into separate lists directly, moving through all cells of the entire row (I was needed the first row cells also):



        public TableElements getTableElements() throws Exception {
        if (getColumnsList()!=null) {

        List<WebElement> elements = getColumnsList();
        List<String> columnNames = new ArrayList<>();
        List<String> rowValues = new ArrayList<>();
        ListIterator<WebElement> listItr = null;
        int columnsNumber = elements.size();
        System.out.println("columnsNumber is: " + columnsNumber + " in " + driver.findElement(By.xpath(datasource)).getText());
        WebElement cell = driver.findElement(By.xpath(getValue("firstColumnXpath")));
        cell.click();
        listItr = elements.listIterator();
        while (listItr.hasNext()) {
        columnNames.add(listItr.next().getText());
        rowValues.add(driver.switchTo().activeElement().getText());
        driver.switchTo().activeElement().sendKeys(Keys.ARROW_RIGHT);
        }
        return new TableElements(columnNames, rowValues);
        }
        else {
        return new TableElements(null, null);
        }
        }

        public List<WebElement> getColumnsList() throws Exception {
        if (CSSElementExists(getValue("columnLabelsCSS")))
        return driver.findElements(By.xpath(getValue("columnLabelsXpath")));
        return null;
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 4 at 20:06

























        answered Jan 4 at 19:55









        Grigoriy YuschenkoGrigoriy Yuschenko

        213




        213
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998459%2fthe-list-of-table-elements-found-by-xpath-contains-only-visible-ten-elements-wit%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules