Может кто-нибудь помочь мне в достижении следующего, но с использованием HashMap
. Я не эксперт по использованию HashMap
s.
Код с массивом
WebElement xmlResponse = iframeElements9.findElement(By.name("currentContactInfo.messageRecord.resMsg"));
WebElement xmlRequest = iframeElements9.findElement(By.name("currentContactInfo.messageRecord.reqMsg"));
WebElement[] listOfElements = {xmlRequest,xmlResponse};
FileHandlers outputToTextFile = new FileHandlers();
ConvertOutputToXML convert = new ConvertOutputToXML();
String textAreaValue=null;
String FileName = null;
org.w3c.dom.Document xmlOutput = null;
//iterating through the Array, this works fine but would like to achieve the same using hashmap
for (int j=0;j<listOfElements.length; j++){
textAreaValue = listOfElements[j].getText(); //using the Hashmap I would like to invoke getText
FileName = outputToTextFile.writeToFile(textAreaValue);// i then write this output to a file
convert.ReadTextFile(FileName);
xmlOutput = (org.w3c.dom.Document) convert.convertToXML(textAreaValue);
}
Код с HashMap
HashMap<String, WebElement> XMLData = new HashMap<>();
XMLData.put("reqMsg",xmlRequest);
XMLData.put("resMsg",xmlResponse);
for (int i = 0; i < XMLData.size(); i++)
{
System.out.println(XMLData.get(i).getText()); //null pointer exception is what I get
}
В идеале я хотел бы использовать ключ "reqMsg" или "resMsg", чтобы затем записать вывод из текстовой области в файл, каждое сообщение в своем собственном файле, используя массив, работает нормально, но просто нужны ключи.