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

    // 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 spearLabel =
            WebAutomation.driver
                .findElement(By.xpath("//*[@id=\"show_units\"]/div/table/tbody/tr[" + i + "]"))
                .getText();
        if (substring(spearLabel, 2, 7).equals("Spear")
            || substring(spearLabel, 3, 8).equals("Spear")
            || substring(spearLabel, 4, 9).equals("Spear")
            || substring(spearLabel, 5, 10).equals("Spear")
            || substring(spearLabel, 6, 11).equals("Spear")
            || substring(spearLabel, 7, 12).equals("Spear")) {
          TroopsDetailPanel.setSpearLabel(
              WebAutomation.driver
                  .findElement(
                      By.xpath("//*[@id='show_units']/div/table/tbody/tr[" + i + "]/td/strong"))
                  .getText());
          break;
        }
        // the troop was not found
        else {
          TroopsDetailPanel.setSpearLabel("0");
        }
      } catch (NoSuchElementException e) {
      }
    }
  }