В MultiValuedMap я сохраняю {локатор} и {текст, найденный в этом локаторе} на веб-странице как пару "ключ-значение". Но когда я пытаюсь получить эту пару «ключ-значение» с помощью метода multiValuedMap.entries (), он получает пару «ключ-значение» неупорядоченным образом.
MultiValuedMap<String, String> multiValuedMap3;
multiValuedMap3 = new ArrayListValuedHashMap();
Collection<String> values4 = multiValuedMap2.get( "Books");
// Output - I am getting locators for webpage objects like
[Menu1Locator1,Menu1Locator2,Menu1Locator3,Menu1Locator4,Menu1Locator5]
Iterator<String> it2 = values4.iterator();
//Iterating locator values from values4 and reading text for object representated by that locator
while (it2.hasNext()) {
String key5 = it2.next();
System.out.print("\n Locator Value = " + key5 +"\n");
String menu1txtFromUI = driver.findElement(By.cssSelector(key5)).getText();
System.out.print("\n\n Text represented by locator is = " + menu1txtFromUI +"\n\n");
multiValuedMap3.put(key5, menu1txtFromUI);
}
Collection<MultiKeyMap.Entry<String, String>> entries3 = multiValuedMap3.entries();
System.out.print("\n\nAll multiValuedMap3 Key-Value Mappings entries " + entries3);
Вывод -
Locator Value = .nav-b > span:nth-child(1)
Text represented by locator is = Books
Locator Value = #nav-subnav > a:nth-child(2) > span:nth-child(1)
Text represented by locator is = Advanced Search
Locator Value = #nav-subnav > a:nth-child(3) > span:nth-child(1)
Text represented by locator is = New Releases & Pre-orders
Locator Value = a.nav-hasArrow:nth-child(4) > span:nth-child(1)
Text represented by locator is = Best Sellers
Locator Value = a.nav-hasArrow:nth-child(5) > span:nth-child(1)
Text represented by locator is = Browse Genres
Locator Value = a.nav-hasArrow:nth-child(6) > span:nth-child(1)
Text represented by locator is = Children's & Young Adult
Locator Value = a.nav-hasArrow:nth-child(7) > span:nth-child(1)
Text represented by locator is = Textbooks
Locator Value = a.nav-hasArrow:nth-child(8) > span:nth-child(1)
Text represented by locator is = Exam Central
Locator Value = a.nav-hasArrow:nth-child(9) > span:nth-child(1)
Text represented by locator is = All Indian Languages
All multiValuedMap3 Key-Value Mappings entries
[#nav-subnav > a:nth-child(2) > span:nth-child(1)=Advanced Search,
a.nav-hasArrow:nth-child(6) > span:nth-child(1)=Children's & Young Adult,
a.nav-hasArrow:nth-child(4) > span:nth-child(1)=Best Sellers,
a.nav-hasArrow:nth-child(9) > span:nth-child(1)=All Indian Languages,
#nav-subnav > a:nth-child(3) > span:nth-child(1)=New Releases & Pre-orders,
a.nav-hasArrow:nth-child(5) > span:nth-child(1)=Browse Genres,
a.nav-hasArrow:nth-child(7) > span:nth-child(1)=Textbooks,
.nav-b > span:nth-child(1)=Books,
a.nav-hasArrow:nth-child(8) > span:nth-child(1)=Exam Central]
Я ожидаю, что вывод multiValuedMap3.entries () будет соответствовать порядку, указанному в первой части приведенного выше вывода.
Почему вывод multiValuedMap3.entries () не упорядочен? Это ожидаемое поведение? Если нет, то как вернуть упорядоченные пары ключ-значение из multiValuedMap3.entries ()?