Beispiel #1
0
  // Sends the number of catapults to the GUI
  public static void setCatapult() {

    // loop through all the show unit lines
    // if the unit name is found then display it on the GUI
    for (int i = 1; i < 15; i++) {
      try {
        String catapultLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"show_units\"]/div/table/tbody/tr[" + i + "]"))
                .getText();
        if (substring(catapultLabel, 2, 10).equals("Catapult")
            || substring(catapultLabel, 3, 11).equals("Catapult")
            || substring(catapultLabel, 4, 12).equals("Catapult")
            || substring(catapultLabel, 5, 13).equals("Catapult")
            || substring(catapultLabel, 6, 14).equals("Catapult")
            || substring(catapultLabel, 7, 15).equals("Catapult")) {
          TroopsDetailPanel.setCatapultLabel(
              WebAutomation.driver
                  .findElement(
                      By.xpath("//*[@id='show_units']/div/table/tbody/tr[" + i + "]/td/strong"))
                  .getText());
          break;
        }
        // the troop was not found
        else {
          TroopsDetailPanel.setCatapultLabel("0");
        }
      } catch (NoSuchElementException e) {
      }
    }
  }