diff --git a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/IKOrganizationScraper.java b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/IKOrganizationScraper.java index cbc4b0f..c4abb75 100644 --- a/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/IKOrganizationScraper.java +++ b/helpmehelpapplication/src/main/java/ntnu/sytemutvikling/team6/models/IKOrganizationScraper.java @@ -36,9 +36,6 @@ public boolean updateData() { WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("table"))); - // Loops through table rows and columns - List rows = driver.findElements(By.cssSelector("table tbody tr")); - String name = null; String telephone = null; String location = null; @@ -47,28 +44,38 @@ public boolean updateData() { // Clear old data before updating this.organizationData.clear(); - for (WebElement row : rows) { - List columns = row.findElements(By.tagName("td")); + // Loops through table rows and columns + List rows = driver.findElements(By.cssSelector("table tbody tr")); + + for (int i = 0; i < rows.size(); i++) { + List columns = rows.get(i).findElements(By.tagName("td")); - for (int i = 0; i < columns.size(); i++) { + // Create organization with category names for csv file + if (i == 0) { + var categories = new Organization("Name", "Telephone", "Location", "Status"); + this.organizationData.add(categories); + continue; + } - WebElement column = columns.get(i); + for (int j = 0; j < columns.size(); j++) { + + WebElement column = columns.get(j); // Non-verification columns - if (i == 0) { + if (j == 0) { name = column.getText(); } - if (i == 1) { - telephone = columns.get(i).getText(); + if (j == 1) { + telephone = columns.get(j).getText(); } - if (i == 2) { - location = columns.get(i).getText(); + if (j == 2) { + location = columns.get(j).getText(); } // Verification column - if (i == 3) { + if (j == 3) { if (!column.findElements(By.cssSelector(".status-pre-approved")).isEmpty()) { status = "Monitored"; } else if (!column.findElements(By.cssSelector(".status-approved")).isEmpty()) { @@ -84,9 +91,6 @@ public boolean updateData() { } driver.quit(); - // Removes the first empty row that lists only the categories, aka no relevant data - this.organizationData.removeFirst(); - return true; }