I’m doing automation to a player and click on that player . I worked on tool. instead of xpath i used tagname to take data from . because in localized control type does support only tagname.
this is my code

 for(int currentPlayerIndexFromUI = 0; currentPlayerIndexFromUI < total.size(); currentPlayerIndexFromUI++){
        // Here we have items collected on UI and start iterating one by one
        // Take the current value from list
        String game = total.get(currentPlayerIndexFromUI);
        // Now we start iterating cells in excel line
        // We know that first player is placed in the cell with index 1
        for(int currentPlayerCellIndexInExcel = 1; currentPlayerCellIndexInExcel < 6; currentPlayerCellIndexInExcel += 2){
            // Take the next player from excel
            String nameFomExcel = event.getRow(i).getCell(currentPlayerCellIndexInExcel).getStringCellValue();
            // We also know that the position is alsways next to the player in excel, so we do not need "k". We just shiift player cell +1 to get position
            String positionInExcel = event.getRow(i).getCell(currentPlayerCellIndexInExcel + 1).getStringCellValue();

            // Now we check the current player from excel equals to the current player from UI list
            // If no, just move to the next player from excel (move 2 cells to the right in our "i" line)
            if(game.equals(nameFomExcel)){
                // If current player in UI is equal to current player from excel, then we take list of date elements for current player in UI(whatever date elements mean)
                WebElement away = AppSession.findElementByAccessibilityId("DgViewAwayTeam");
                List<WebElement> date = away.findElements(By.tagName("./*[contains(@LocalizedControlType, 'item')]"));
                // start iterating by the list of date list
                for(int z=0;z<date.size();z++) //30
                {
                    // Extract position from current date item
                    String value=date.get(z).getAttribute("Name").substring(0, 1);
                    System.out.println(value);
                    if (value.equals(positionInExcel))
                    {
                        // if the position matches to the player position from excel then click item on UI
                        date.get(z).click();
                        // Our logic assumes there won't be more clicks so we can break current loop
                        break;
                    }

                }
                // After finishing the loop above we are sure that we successfully handled player/position pair and we may break the loop which we have got into after breaking loop above
                // Hence after breaking the current loop we'll move for processing neew player item from UI .

            }
        }
    }

In the app UI have 6 rows , inside each row have 4 columns, in that columns contains uniform number, player name, positions (F, C, G)…….
i did fetch the player from ui and store it in variable total it is array list…
My code works is selecting first player ,click on first row C,G,F….
I debug the code, it is looping is working correctly…
the real problem is in the z loop, here date means i am collecting all columns values to store in in date variable, that is am looping…its size is 0 to 30….
first time it click on first player it is in the excel and click on its position ‘C’, THEN break, then again comes to click on same column different position….

WebElement away = AppSession.findElementByAccessibilityId("DgViewAwayTeam");
                List<WebElement> date = away.findElements(By.tagName("./*[contains(@LocalizedControlType, 'item')]"));
                // start iterating by the list of date list
                for(int z=0;z<date.size();z++) //30
                {
                    // Extract position from current date item
                    String value=date.get(z).getAttribute("Name").substring(0, 1);

instead of this code.. how do i select player for position…?
I am selecting 3 player for their respective positions….
enter image description here

Any help much appreciated…



Source link https://sqa.stackexchange.com/questions/34929/how-to-select-each-row-for-respective-column-in-ui-using-winapp-driver

LEAVE A REPLY

Please enter your comment!
Please enter your name here