Esempio n. 1
0
  // Sends the level of villageHQ to the GUI
  public static void setVillageHQ() {

    // loop through the building rows
    for (int i = 2; i < 20; i++) {
      try {
        String villageHQLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"buildings\"]/tbody/tr[" + i + "]/td[1]"))
                .getText();

        // if the building was found then set the name and level
        if (substring(villageHQLabel, 0, 7).equals("Village")) {
          BuildPanel.setVillageHQLabel("Village HQ " + substring(villageHQLabel, 21, 31));

          // if the building level is not present then make it level 0
          if (substring(villageHQLabel, 21, 31).equals("")) {
            BuildPanel.setVillageHQLabel("Village HQ (Level 0)");
            BuildPanel.setVillageHQButtonTrueOrFalse(false);
          }
          break;
        }
        // if the building is not found at all make it level 0
        else {
          BuildPanel.setVillageHQLabel("Village HQ (Level 0)");
        }
      }
      // if the element does not exist on the webpage then it's max level
      catch (NoSuchElementException e) {
        BuildPanel.setUpgradeVillageHQLabel("Cannot upgrade");
        BuildPanel.setVillageHQButtonTrueOrFalse(false);
        BuildPanel.setVillageHQLabel("Village max level");
      }
    }
  }