1

I am working in windows application automation testing. I want to perform a multiple task like to select a player name and its position. My application is a baseball reporter software. so, I'm automating to select 8 players from the table. I keep the player names and their positions in excel sheet. my application manual working process for selecting a line ups is to double click a player and then another box comes to select a position of those player. my issue is that I am double clicking on wrong element....how I perform double click on that exact player ?

this is the code..

 public class LineUps  {



        private WiniumDriver driver;
        public LineUps(WiniumDriver driver) throws MalformedURLException, InterruptedException {
            this.driver=driver;
        }

        public  void away_team_lineups_excel()
        {
               try {
                   driver.findElementById("lblAwayTeamHittersAll").click();
                   WebElement away_players_list1 = driver.findElementById("lsvAwayTeamHitters1");
                   WebElement away_players_list2 = driver.findElement(By.id("lsvAwayTeamHitters2"));

                   List<WebElement> away_team_players_lineups1 = away_players_list1.findElements(By.xpath("./*[contains(@LocalizedControlType, 'item')]"));
                   List<WebElement> away_team_players_lineups2 = away_players_list2.findElements(By.xpath("./*[contains(@LocalizedControlType, 'item')]"));


                   List<String> away_players1 = new ArrayList<String>();
                   for(int i=0;i<away_team_players_lineups1.size();i++)
                   {
                   List<WebElement> away_team_players_names = away_team_players_lineups1.get(i).findElements(By.xpath("./*[contains(@LocalizedControlType, 'text')]"));                 
                       for(int j=3;j<away_team_players_names.size();j++)
                       {
                           String celtext = away_team_players_names.get(j).getAttribute("Name");
                          // System.out.println(celtext);
                           away_players1.add(celtext);
                       }

                   }                  
                   List<String> away_players2 = new ArrayList<String>();
                   for(int j=0;j<away_team_players_lineups2.size();j++)
                   {
                   List<WebElement> away_team_players_names2 = away_team_players_lineups2.get(j).findElements(By.xpath("./*[contains(@LocalizedControlType, 'text')]"));
                   for(int k=3;k<away_team_players_names2.size();k++)
                       {
                           String celtext = away_team_players_names2.get(k).getAttribute("Name");
                         //  System.out.println(celtext);
                           away_players2.add(celtext);

                        }
                   }
                   away_players2.addAll(away_players1);
                   List<String> away_players3 = new ArrayList<String>();
                   away_players3.addAll(away_players2);
                   System.out.println(away_players3);
                   System.out.println(away_players3.size());
                   System.err.close();
                   System.setErr(System.out);
                   File f= new File("player.xlsx");
                  FileInputStream fs= new FileInputStream(f);
                 XSSFWorkbook wb= new XSSFWorkbook(fs);
                   XSSFSheet bb_players= wb.getSheetAt(0);

                int rowcount= bb_players.getLastRowNum();
                         System.out.println("Total rows is: " +rowcount);
                         Actions act= new Actions(driver);

                       for(int i=1; i<=rowcount; i++)                                
                       {
                      String player = bb_players.getRow(i).getCell(0).getStringCellValue();
                      String position = bb_players.getRow(i).getCell(1).getStringCellValue();

                      for(int j=0; j<away_players3.size(); j++)
                      {

                       String away_total_players= away_players3.get(j);



                    if(!away_total_players.equals(player))
                        {

                         break; 

                        }
                    else
                    {

                        WebElement line_up1=driver.findElementByLinkText(player);
                        System.out.println(line_up1);

                         act.moveToElement(line_up1).doubleClick().build().perform();;


                    }

                            WebElement away_players_pos = driver.findElementById("PlayerPositions");
                             List<WebElement> player_pos = away_players_pos.findElements(By.xpath("./*[contains(@ControlType,'Button')]"));
                             if(position.equals(player_pos.get(i)))
                             {
                                   player_pos.get(i).click();
                             }


                       }


                }



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


        }

}

Excel sheet

Screenshot

how to double click on the particular name webelement ?

Firstly I want try whether I can able to select one player and its position, then I can add loops to select multiple players... Inside action class my element must be wrong, that's why double click is not working a single player. how I write the matching webelement on inside action class.... How to perform double click on the first player "Happ Ian" and select its position "CF"

anybody please help me

1
  • @Alexey R. please check my question
    – user32519
    May 29, 2018 at 17:58

1 Answer 1

1

To double-click on a particular element, you first have to move to that element.

Actions act= new Actions(driver);
for(i=0;i<9;i++){
WebElement player = driver.findElement(By.linkText(i));
act.moveToElement(player).doubleClick().build();
act.perform();
}

Check if this solves your problem.

7
  • Its showing error like away_team_players_names2 cannot be resolved
    – user32519
    May 30, 2018 at 4:04
  • do you want to select the player which is in the first position?? If yes, then you can try to point at the first position using xpath, id, linkText, etc. WebElement player = driver.findElement(by.linkText("1")); act.moveToElement(player).doubleClick().build();
    – Rishikesh
    May 30, 2018 at 4:56
  • @Anthony Manually, does double-clicking on the player's numbers also selects the respective player???
    – Rishikesh
    May 30, 2018 at 6:40
  • @Anthony I have updated the answer, check if this helps. I am assuming that double-clicking on the number, selects the player corresponding to that number.
    – Rishikesh
    May 30, 2018 at 10:45
  • winium does not support linkText .please tell me any other solution
    – user32519
    Jun 4, 2018 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.