i have a list of urls and i am opening each line in a browser and then collecting some values into HashMap. When i print the values collected in HashMap, i see that it repeats every previous value. what am i doing wrong?
here is what the url look like:
- https://myurl.com/test1111
- https://myurl.com/test2222
- https://myurl.com/test3333
- https://myurl.com/test4444
- https://myurl.com/test5555
and the is what the HashMap print looks like:
- test1111 | file available
- test2222 | file available
- test1111 | file available
- test2222 | file available
- test3333 | file not available
- test1111 | file available
- test2222 | file available
- test4444 | file available
- test3333 | file not available
- test1111 | file available
- test2222 | file available
- test4444 | file available
- test5555 | file available
- test3333 | file not available
- test1111 | file available
- test2222 | file available
- test4444 | file available
- test5555 | file available
- test6666 | file available
- test3333 | file not available
- test7777 | file not available
here is my entire code:
public class Access_file{
public static void readFile() throws IOException {
HashMap<String, String> values = new HashMap<String, String>();
CSVReader reader = null;
System.setProperty("webdriver.chrome.driver", "chromedriver");
WebDriver driver = new ChromeDriver();
try {
reader = new CSVReader(new FileReader("x_url.csv"), ',');
String[] nextLine;
while((nextLine = reader.readNext()) != null) {
for(String line : nextLine) {
driver.get(line);
String[] url_split = line.split("/");
String test_url = url_split[4];
String availability = driver.findElement(By.cssSelector("#mySelector']")).getText();
values.put(test_url, availability);
}
for(String i : values.keySet()) {
System.out.println(i + "|"+ values.get(i));
}
}
}
catch (NoSuchElementException e) {
e.printStackTrace();
}
finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}