Home » Java » How to select the list of players in the above order?

How to select the list of players in the above order?

Posted by: admin June 30, 2018 Leave a comment

Questions:

screenshot of players selection.I’m automating baseball sports reporter application. My application is a desktop application. I’m using winium tool with java language.

These are the players that i need to select::

  #players names  ::  positions
 Happ            = CF
 Bryant          = 3B
 Rizzo           = 1B
 Contreras       = C
 Schwarber       = LF
 Russell         = SS
 Heyward         = RF
 Baez            = 2B
 Chatwood        = P

now i need to select the particular players that I mentioned above list order.
My application manual working process is first double click a player and mean time a window came to select the position by single click. etc..

public void awayTeamHitters() {


        try
        {
        String[] players = new String[]
                {
                "Happ, Ian#","Bryant, Kris","Rizzo, Anthony*","Contreras, Willson","Schwarber, Kyle*","Russell, Addison","Heyward, Jason*","Baez, Javier"
                };
        String[] positions=new String[]
                {
                        "CF","3B","1B","C","LF","SS","RF","2B"
                };


            List<String> playersInList = Arrays.asList(players);
            List<String> positionsInlist=Arrays.asList(positions);


            //selecting players   
            WebElement table = driver.findElement(By.xpath(".//*[@AutomationId='lsvAwayTeamHitters1']"));
            List<WebElement> rows = table.findElements(By.xpath("./*[contains(@LocalizedControlType, 'item')]"));
            for (WebElement row : rows) {
                List<WebElement> cols = row.findElements(By.xpath("./*[contains(@LocalizedControlType, 'text')]"));
                for (WebElement col : cols) {
                    String celtext = col.getAttribute("Name");
                    if (playersInList.contains(celtext)) {
                        Actions act = new Actions(driver);
                         act.doubleClick(col).build().perform();


                         //selecting positions
                        WebElement pos= driver.findElementById("PlayerPositions");
                         List<WebElement> rowpos=pos.findElements(By.xpath("./*[contains(@LocalizedControlType, 'button')]"));
                         for (WebElement val : rowpos) {
                             String postext = val.getAttribute("Name");
                             System.out.println(postext);
                             if(positionsInlist.contains(postext)) {
                                val.click();
                             }

                    }                                                     
                }

                }
            }
        }




    catch (Exception e) {
        System.out.println(e);
    }
}

}

Here getting output is first selecting this player Baez and then select position is RF, and then select Contreras and select position RF.. how to select the above order and i have other issue is the player names contains in the 2 list box as the above screenshot…and automation id is lsvAwayTeamHitters2…

this is the output i’m getting now..
output screenshot

Answers: