0

I'm using LinkedHashMap inorder to validate the webelement link text. Storing all the link texts as key and weblement name as value.

but in the output, it only gives the first 3 key and values and repeating them 2 times. I used the same code without using WebElement as second parameter and choose the string like LinkedHashMap, it works fine then.

What is wrong with my code below using WebElement as 2nd param.

E.g. below

 LinkedHashMap<String,WebElement> testLinks1 = new 
     LinkedHashMap<String,WebElement>();
            testLinks1.put("XYZ",webelement1);
            testLinks1.put("Tasks",webelement2);
            testLinks1.put("ABC",webelement13);
            testLinks1.put("Annual",webelement4);
            testLinks1.put("Buyout",webelement5);
            testLinks1.put("Initial",webelement6);
            testLinks1.put("Clearing",webelement7);

      for(Map.Entry<String,WebElement> entry : testLinks1.entrySet()){
             String key = entry.getKey();    
             System.out.println("Key : " + entry.getKey() + " Value : " + entry.getValue());                                
     }

OutPut:

Key : XYZ Value : [[ChromeDriver: chrome on XP (5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-2]
Key : Tasks Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-3]
Key : ABC Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-4]
Key : XYZ Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-2]
Key : Tasks Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-3]
Key : ABC Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-4]
Key : XYZ Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-2]
Key : Tasks Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-3]
Key : ABC Value : [[ChromeDriver: chrome on XP
(5bcee8b6300baeb78b432667ce2ed36b)] -> id: test-name-4]

Lucky
  • 107
  • 3
  • 9
  • Are you sure that this is reproducible with just the code sample you have provided? Why are two maps: smSubMenuLinks1 & testLinks1 used? Is it reproducible with one map only? If yes, removing one would help people trying to help. Also, you are just adding 2 entries to the map in the above code snippet, why do expect more to be printed? – Harish Feb 17 '18 at 03:03
  • Harish, thanks for replying and pointing the mistake i did. I updated my code above and to answer your question, yes its reproducible and displaying the first 3rd entries multiple times as you can see in the output. Please let me know if you have any other question or any suggestion – Lucky Feb 18 '18 at 02:49

0 Answers0