/**
   * @param driver webdriver object to access the browser
   * @param term the search term expected in the results
   * @return is it true or not
   */
  public static Boolean isInSearchResults(WebDriver driver, String term, Integer pageCounter) {
    Boolean result = Boolean.FALSE;
    String xpath = "//tr[@class='csc-row']/td/a[text()='" + term + "']";
    String textTemplate;
    String currentPageIndicatorFieldText;

    if (!driver.findElements(By.xpath(xpath)).isEmpty()) {
      result = Boolean.TRUE;
    } else {
      try {
        driver.findElement(By.className("flc-pager-next")).click();
        new WebDriverWait(driver, 10)
            .until(
                ExpectedConditions.invisibilityOfElementLocated(
                    By.className("cs-loading-indicator")));

        pageCounter += 1;
        WebElement textField = driver.findElement(By.xpath("//*[@id=\"pager-bottom\"]/li[5]"));

        textTemplate = "Viewing page " + pageCounter + ".";
        currentPageIndicatorFieldText = textField.getText();

        if (!(currentPageIndicatorFieldText.contains(textTemplate))) {
          return Boolean
              .FALSE; // fixes infinite loop of button-clicking when the item is not found.
        }
        result = isInSearchResults(driver, term, pageCounter);
      } catch (Exception e) {
        log(e.getMessage());
      }
    }
    return result;
  }
示例#2
0
  @Ignore("WIP")
  @Test
  public void testNumberOfRegions() throws InterruptedException {

    driver.findElement(By.xpath("//a[text()='Data Browser']")).click();

    Thread.sleep(1000);
    List<WebElement> regionList = driver.findElements(By.xpath("//ul[@id='treeDemo']/li"));
    String regions = JMXProperties.getInstance().getProperty("regions");
    String[] regionName = regions.split(" ");
    for (String string : regionName) {}
    // JMXProperties.getInstance().getProperty("region.R1.regionType");
    int i = 1;
    for (WebElement webElement : regionList) {
      // webElement.getAttribute(arg0)
      i++;
    }

    driver.findElement(By.id("treeDemo_1_check")).click();

    List<WebElement> memeberList = driver.findElements(By.xpath("//ul[@id='membersList']/li"));
    int j = 0;
    for (WebElement webElement : memeberList) {
      j++;
    }
  }
  protected void selectOptionByLabel(WebElement menuElement, String text, boolean guardAjax) {
    String menuId = getEscapedElementId(menuElement);
    WebElement trigger = menuElement.findElement(By.cssSelector("div.ui-selectonemenu-trigger"));
    trigger.click();

    String menuItemsContainerId = menuId + "_panel";
    List<WebElement> options =
        driver.findElements(
            By.cssSelector("#" + menuItemsContainerId + " tr.ui-selectonemenu-item"));
    if (options.isEmpty()) {
      options =
          driver.findElements(
              By.cssSelector("#" + menuItemsContainerId + " li.ui-selectonemenu-item"));
    }
    String selectedOptionText = getSelectedOptionText(menuElement);
    for (WebElement option : options) {
      if (option.getAttribute("data-label").equals(text)) {
        if (guardAjax && !selectedOptionText.equals(text)) {
          Graphene.guardAjax(option).click();
        } else {
          option.click();
        }
        break;
      }
    }
  }
  /**
   * 取得新闻标题、时间和评论数的集合
   *
   * @param urls 所有新闻URL集合
   * @return 新闻标题、时间和评论数的集合
   */
  public static List<String> getTimeAndJoin(List<String> urls) {
    List<String> listTimeAndJoin = new ArrayList<String>();

    int num = 1;
    // System.setProperty("webdriver.ie.driver", "." + File.separator + "Driver" + File.separator +
    // "IEDriverServer.exe");
    // WebDriver driver = new InternetExplorerDriver();
    WebDriver driver = new FirefoxDriver();
    for (int i = 0; i < urls.size(); i++) {
      // System.setProperty("webdriver.ie.driver", "." + File.separator + "Driver" + File.separator
      // + "IEDriverServer.exe");
      // WebDriver driver = new InternetExplorerDriver();
      driver.get(urls.get(i));
      List<WebElement> headline =
          driver.findElements(By.cssSelector("div[class='atitle tCenter']"));
      List<WebElement> timeAndJoin = driver.findElements(By.cssSelector("div[class='about']"));

      StringBuffer sb = null;
      sb = new StringBuffer();

      if ((timeAndJoin.size() == 1) && (headline.size() == 1)) {
        sb.append("[新闻 " + num + "]");
        sb.append(headline.get(0).getText() + "\t");
        String[] temp = timeAndJoin.get(0).getText().split("\n");
        sb.append(temp[0] + "\t" + temp[1] + "\t" + temp[2]);
        // sb.append(timeAndJoin.get(0).getText().replaceAll("\\s+", ""));
        listTimeAndJoin.add(sb.toString());
        num++;
      }
      // driver.close();
    }
    driver.close();
    return listTimeAndJoin;
  }
示例#5
0
  private void accept(WebDriver driver, String message) {
    StopWatch stopWatch = new Log4JStopWatch();
    stopWatch.start();

    WebElement img = driver.findElement(By.xpath("//img[@alt='Click to sign']"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
    img.click();

    List<WebElement> signed_imgs = driver.findElements(By.xpath("//img[@alt='Signed']"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);

    if (signed_imgs.size() != 0) {
      stopWatch.stop("accept", message);
    } else {
      randomDelay();
      stopWatch.start();
      WebElement awsForm = driver.findElement(By.name("awsForm"));

      driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
      awsForm.submit();

      signed_imgs = driver.findElements(By.xpath("//img[@alt='Signed']"));
      driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
      stopWatch.stop("accept'", message);
    }
  }
  @SuppressWarnings("deprecation")
  @Test
  public void booking() {

    // click to choose book services
    //			driver.findElement(By.xpath(".//*[@id='gt_sr']")).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Click to choose service
    driver.findElement(By.xpath(Bookingpage.Service)).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Click to choose staff
    driver.findElement(By.xpath(Bookingpage.Staff1)).click();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // Click to choose date
    List<WebElement> date = driver.findElements(By.xpath(Bookingpage.TodayDate));

    String selectedDate = date.get(0).getText();
    driver.findElement(By.linkText(selectedDate)).click();

    // List the timeslots
    List<WebElement> availslots = driver.findElements(By.xpath(Bookingpage.Timeslot));
    int bookings = availslots.size();
    System.out.println(" Time slots size :: " + bookings);
    try {
      if (bookings > 0) {
        String[] slots1 = new String[bookings];
        int j = 0;
        // System.out.println(" available slots :: "+availslots);
        for (WebElement avail : availslots) {
          slots1[j] = avail.getText();
          System.out.println(slots1[j]);
          j++;

          for (String SelectedSlot : slots1) {

            System.out.println("Selected SLot :: " + SelectedSlot);
            driver.findElement(By.linkText(SelectedSlot)).click();

            driver.findElement(By.id("cust-IName")).sendKeys("Vimal Tester");

            // Click on continue
            driver.findElement(By.xpath(".//*[@id='cust-continue']")).click();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            // Book My Appointment
            driver.findElement(By.className("global_btn2_rt")).click();
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
          }

          break;
        }
      } else {
        System.out.println("slot not available");
      }
    } catch (Exception e) {
      Log.info("Exception " + e.getMessage());
    }
  }
示例#7
0
  public static void main(String[] args) throws InterruptedException {

    WebDriver driver = new FirefoxDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.manage().window().maximize();
    driver.get("http://facebook.com");

    driver.findElement(By.xpath("//input[@id='email']")).sendKeys("*****@*****.**");
    driver.findElement(By.xpath("//input[@id='pass']")).sendKeys("Temp@123");
    driver.findElement(By.xpath("//input[@id='pass']")).sendKeys(Keys.ENTER);

    driver.findElement(By.xpath("//div[@id='pagelet_welcome_box']/div/a")).click();
    driver.findElement(By.xpath("//div[@id='fbTimelineHeadline']/div[2]/div/a[4]")).click();

    List<WebElement> friends = driver.findElements(By.xpath("//div[@class='fsl fwb fcb']/a"));
    System.out.println("Total friends -> " + friends.size());
    int newFriends = friends.size(); // 20 40 60
    Actions act = new Actions(driver);

    int oldFriends = 0; // 0 20 40 60
    while (newFriends != oldFriends) {
      oldFriends = newFriends;
      WebElement lastFriend = friends.get(friends.size() - 1);
      act.moveToElement(lastFriend).build().perform(); // 20th
      Thread.sleep(3000);
      friends = driver.findElements(By.xpath("//div[@class='fsl fwb fcb']/a"));
      newFriends = friends.size();
      System.out.println("Total friends -> " + friends.size());
    }

    System.out.println("FINAL Total friends -> " + friends.size());
    for (int i = 0; i < friends.size(); i++) {
      System.out.println(friends.get(i).getText());
    }
  }
  // Method checking if the edited profile is displayed back to the user and if illegal string like
  // URL and email id are stripped off from "profile essay" sections
  private void verifyChanges() {

    List<WebElement> allElements = driver.findElements(By.cssSelector("div[id='about_myself'] p"));
    for (WebElement element1 : allElements) {
      if (element1.getText().contains("www.") || element1.getText().contains(".com")) ;
      ripOffTextAboutMe++;
    }

    List<WebElement> allElements2 =
        driver.findElements(By.cssSelector("div[id='who_im_looking_for'] p"));

    for (WebElement element2 : allElements2) {
      if (element2.getText().contains("www.") || element2.getText().contains(".com")) ;
      ripOffTextPartnerSearch++;
    }

    List<WebElement> allElement3 =
        driver.findElements(By.cssSelector("ul[class='profileInformation'] li"));
    for (WebElement element3 : allElement3) {
      // System.out.println(element3.getText());
      if (element3.getText().contains("Mixed") || element3.getText().contains("4ft. 10in."))
        profileChangeCheck++;
    }

    if (profileChangeCheck > 0)
      System.out.println("SUCCESS: The changes made in the basic profile are visible");

    if (ripOffTextAboutMe != 0)
      System.out.println(
          "SUCCESS: The About Myself section has ripped off any illegal strings like URL and Email id");

    if (ripOffTextPartnerSearch != 0)
      System.out.println(
          "SUCCESS: The What I am Looking For section has ripped off any illegal strings like URL and Email id");
  }
示例#9
0
  /**
   * Paste the current content in the clipboard into a specific target, will wait for ajax refresh
   *
   * @param target the target's label to paste in
   * @return this agent
   * @throws Exception
   */
  public ClipboardAgent pasteContent(String target, boolean isAjaxList) throws Exception {

    String pasteSelectorPrefix = "//h2[contains(text(),'" + target + "')]";
    String pasteSelectorSuffix =
        "/button[contains(@class, 'clipboard') and contains(@title, 'Paste')]";

    // Slots
    String pasteSelector = pasteSelectorPrefix + "/../" + pasteSelectorSuffix;

    WebDriver webDriver = guiAgent.getWebDriver();

    if (webDriver.findElements(By.xpath(pasteSelector)).isEmpty()) {
      // Content lists
      pasteSelector = pasteSelectorPrefix + pasteSelectorSuffix;
    }

    if (webDriver.findElements(By.xpath(pasteSelector)).isEmpty()) {
      pasteSelector = "//fieldset[contains(@class, '" + target + "']/" + pasteSelectorSuffix;
    }

    webDriver.findElement(By.xpath(pasteSelector)).click();

    if (isAjaxList) {
      guiAgent.agentWait().waitForAjaxPageToLoad();
    } else {
      guiAgent.agentWait().waitForPageToLoad();
    }

    return this;
  }
示例#10
0
  @Test
  public void testRegistrationWithSessionStoredPassword() {
    WebDriver driver = driverService.getSharedCleanedWebDriver();
    String randomName = RandomStringUtils.randomAlphabetic(15);

    RegistrationPage registrationPage = RegistrationPage.open(driver);
    registrationPage.register(randomName, "", randomName);
    assertFalse(driver.findElements(By.cssSelector(".alert-error")).isEmpty());

    registrationPage.register(randomName, randomName + "@localhost", "");
    assertTrue(driver.findElements(By.cssSelector(".alert-error")).isEmpty());
  }
示例#11
0
  @Test
  @Parameters({"masterSheetName", "web_ui_framework_installed"})
  public static void isMasterWorkBookPresent(
      String masterSheetName, String web_ui_framework_installed) throws InterruptedException {

    System.out.println(
        "-----------------------------------------------------------------------------------------------");
    System.out.println(
        "PRE-REQ CHECK BEFORE TESTING THE EXPORT WORKBOOK FUNCTIONALITY, IN PROGRESS");
    System.out.println("");
    System.out.println(
        "-----------------------------------------------------------------------------------------------");
    System.out.println("");

    // Thread.sleep(10000);
    web_ui_framework_installed =
        Common.assignPOMValues("BIwebuiframeworkInstalled", web_ui_framework_installed);

    masterSheetName = Common.assignPOMValues("BImasterSheetName", masterSheetName);
    System.out.println("The specified masterWB to search for is " + masterSheetName);

    Thread.sleep(1000);
    if (web_ui_framework_installed.equalsIgnoreCase("installed")) {
      System.out.println("In here");
      driver.switchTo().frame("component-iframe-bigsheets");
    } else {
      // Boolean
      // isDisplayedValue=driver.findElements(By.xpath("//*[@id='widget_searchBox']/div[1]/input[@type='text'][@value='Χ ']")).size()>0;

      Boolean isDisplayedValue =
          driver.findElements(By.xpath("//div[contains(@class,'m2HasValue')]")).size() > 0;
      System.out.println("Search Box has value " + isDisplayedValue);

      if (isDisplayedValue == true) {

        WebElementHelper.findAndClickByXpath(
            driver,
            "//*[@id='widget_searchBox']/div[1]/input[@type='text'][@value='Χ ']",
            60,
            "Filter value");
      }
    }

    Boolean isDisplayed = driver.findElements(By.linkText(masterSheetName)).size() > 0;

    if (isDisplayed == false) {
      System.out.println("In here false");
      System.out.println("Please create the Master WB before proceeding with the Edit");
    }
    Assert.assertEquals(isDisplayed, new Boolean(true));
    WebElementHelper.clickByLinkText(driver, masterSheetName);
  }
示例#12
0
  @Test
  public void testRegistrationOfTakenLogin() {
    WebDriver driver = driverService.getSharedCleanedWebDriver();
    String randomName = RandomStringUtils.randomAlphabetic(15);

    RegistrationPage registrationPage = RegistrationPage.open(driver);
    registrationPage.register(randomName);
    assertTrue(driver.findElements(By.cssSelector(".alert-error")).isEmpty());

    driver.manage().deleteAllCookies();
    registrationPage = RegistrationPage.open(driver);
    registrationPage.register(randomName);
    assertFalse(driver.findElements(By.cssSelector(".alert-error")).isEmpty());
  }
  @Test
  void SearchPatientByAdmin() throws Exception {
    waiting = new WebDriverWait(driver, 20);
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    userName = testprofileTherapist.readNode("username");
    passWord = testprofileTherapist.readNode("password");
    login_User(userName, passWord);
    Thread.sleep(3000);
    //		buttShowMenu=findElementTherapist("menu|showmenubtt");
    //		buttShowMenu.click();
    //		findMenuData("Patients").click();
    sortFirstname = findElementAdmin("sort|firstname");
    sortLastName = findElementAdmin("sort|lastname");
    sortLoginDate = findElementAdmin("sort|logindate");
    sortFirstname.click();
    ListuUserName = driver.findElements(By.id("nameOfUser"));
    sizeListElement = ListuUserName.size();
    nameOfuser = new String[sizeListElement];

    for (int i = 0; i < sizeListElement; i++) {
      String s = ListuUserName.get(i).getText();
      nameOfuser[i] = s;
    }
    Arrays.sort(nameOfuser);
    System.out.println(nameOfuser[0]);
    System.out.println(nameOfuser[1]);
  }
示例#14
0
 public static List<WebElement> createWebElementsList(WebDriver driver, By by) {
   List<WebElement> webElements;
   driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS); // Quickly
   webElements = driver.findElements(by);
   driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
   return webElements;
 }
 public static void main(String[] args) {
   System.setProperty("webdriver.chrome.driver", "C:/WebServerSelenium/chromedriver.exe");
   WebDriver driver = new ChromeDriver();
   driver.navigate().to(Configurations.HOMEPAGE);
   driver.manage().window().maximize();
   try {
     driver
         .findElement(By.xpath("html/body/form/table/tbody/tr/td/div/center[1]/input[1]"))
         .sendKeys("*****@*****.**");
     driver
         .findElement(By.xpath("html/body/form/table/tbody/tr/td/div/center[1]/input[2]"))
         .sendKeys("Asdfghjkl123");
     driver
         .findElement(By.xpath("html/body/form/table/tbody/tr/td/div/center[2]/input[1]"))
         .click();
     driver.findElement(By.xpath("html/body/div/div/table/tbody/tr[2]/td[1]/a")).click();
     driver.findElement(By.xpath("html/body/form/table/tbody/tr/td[1]/input[2]")).click();
     List<WebElement> list =
         driver.findElements(
             By.xpath(
                 "//*[contains(text(),'"
                     + "Nessun paziente selezionato o nessun indirizzo email inserito."
                     + "')]"));
     Assert.assertTrue(
         list.size() > 0, "Nessun paziente selezionato o nessun indirizzo email inserito.");
     System.out.println("Test Passed");
   } catch (AssertionError e) {
     System.out.println("Test Failed");
     System.out.println(e.getMessage());
   }
   driver.close();
 }
示例#16
0
  /**
   * Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not.
   * Returns all elements within the current page DOM.
   *
   * @param WebDriver The driver object to be used
   * @param By selector to find the element
   * @param int The time in seconds to wait until returning a failure
   * @return List<WebElement> all elements within the current page DOM, or null (if the timeout is
   *     reached)
   */
  public static List<WebElement> waitForListElementsPresent(
      WebDriver driver, final By by, int timeOutInSeconds) {
    List<WebElement> elements;
    try {
      driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); // nullify implicitlyWait()

      WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
      wait.until(
          (new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver driverObject) {
              return areElementsPresent(driverObject, by);
            }
          }));

      elements = driver.findElements(by);
      driver
          .manage()
          .timeouts()
          .implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); // reset implicitlyWait
      return elements; // return the element
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
示例#17
0
  public void VerifyAllLinks(WebDriver driver) {

    List<WebElement> ele = driver.findElements(By.tagName("a"));

    System.out.println("size:" + ele.size());

    int isValid;

    for (int i = 0; i < ele.size(); i++) {

      String nextHref = ele.get(i).getAttribute("href");

      isValid = getResponseCode(nextHref);

      if (isValid > 0) {

        System.out.println("isValid = " + isValid + ". Hence, Valid URL.");

      } else {

        System.out.println("isValid = " + isValid + ". Hence, Invalid URL.");
      }
      ;
    }
  }
  @Test
  @Ignore(
      "I would love for this to work consistently but it fails too often between releases to use as an example")
  public void multiSelectWithUserInteractions() {

    WebElement multiSelect;

    multiSelect = driver.findElement(By.cssSelector("select[multiple='multiple']"));
    List<WebElement> multiSelectOptions = multiSelect.findElements(By.tagName("option"));

    // in real life, clicking on a multi select item without holding down
    // CTRL will deselect all others and select only that one item

    Actions actions = new Actions(driver);

    actions
        .click(multiSelectOptions.get(0))
        .click(multiSelectOptions.get(1))
        .click(multiSelectOptions.get(2))
        .perform();

    clickSubmitButton();

    new WebDriverWait(driver, 10).until(ExpectedConditions.titleIs("Processed Form Details"));

    assertEquals(
        "Expected only 1 match",
        1,
        driver.findElements(By.cssSelector("[id^='_valuemultipleselect']")).size());
  }
示例#19
0
  public boolean deleteWebApp(String webAppContext) throws Exception {
    WebElement table_element = driver.findElement(By.id("webappsTable"));
    List<WebElement> tr_collection =
        table_element.findElement(By.tagName("tbody")).findElements(By.tagName("tr"));
    if (tr_collection.size() == 0) {
      throw new Exception("Web App you are trying to delete not exists");
    }
    List<WebElement> td_collection;
    for (WebElement tr : tr_collection) {
      td_collection = tr.findElements(By.tagName("td"));
      if (webAppContext.equals(td_collection.get(1).getText())) {
        td_collection.get(0).findElement(By.tagName("input")).click();
        driver.findElement(By.id("delete2")).click();
        Assert.assertEquals(
            driver.findElement(By.id("messagebox-confirm")).getText(),
            "Do you want to delete the selected applications?",
            "Delete Confirmation message mismatched");
        List<WebElement> buttons = driver.findElements(By.tagName("button"));
        for (WebElement button : buttons) {
          if ("yes".equalsIgnoreCase(button.getText())) {
            button.click();
            break;
          }
        }

        Assert.assertEquals(
            driver.findElement(By.id("messagebox-info")).getText(),
            "Successfully deleted selected applications",
            "Web Application deletion failed" + ". Message box content mis matched");
        driver.findElement(By.xpath("/html/body/div[3]/div[2]/button")).click();
        return true;
      }
    }
    throw new Exception("Web App you are trying to delete not exists");
  }
    public void Test(WebDriver driver, String XPath) {
      // String XPath2 = Regex.Replace(input: XPath, pattern: @"^\/\/", replacement: "");
      String XPath2 = XPath.replaceAll("^\\/\\/", "");
      String[] components = XPath2.split("/");
      String cummulative_xpath = "";
      int i = 0;
      boolean res = false;

      Reset();

      for (String comp : components) {
        i++;
        if (i == 1) {
          cummulative_xpath = "//" + comp;
        } else {
          cummulative_xpath = cummulative_xpath + "/" + comp;
        }

        // Test component
        // ReadOnlyCollection<IWebElement> foundelements =
        // driver.findElements(By.XPath(cummulative_xpath));
        List<WebElement> foundelements =
            Collections.unmodifiableList(driver.findElements(By.xpath(cummulative_xpath)));
        Results.add(
            new Result((foundelements.size() > 0), foundelements.size(), cummulative_xpath));
      }
    }
示例#21
0
  private boolean clickNext(WebDriver driver) {
    while (true) {
      boolean clicked = false;
      int iteration = 0;
      By by = By.className("show-next");
      clickCloseModalIfAny(driver);
      for (WebElement el : driver.findElements(by)) {
        try {
          waitdriver.until(ExpectedConditions.elementToBeClickable(by));
          el.click();
          clicked = true;
          return true;
        } catch (Exception ex) {

        }
      }
      if (!clicked) {
        iteration++;
        continue;
      }
      if (!clicked && iteration > 3) {
        log.error("Element not clickable");
        return false;
      }
    }
  }
 private static void verifySelectFieldIsDefault(String selector, WebDriver driver) {
   String xpath = "//select[contains(@class, '" + selector + "')]";
   for (WebElement element : driver.findElements(By.xpath(xpath))) {
     Select select = new Select(element);
     assertEquals(select.getFirstSelectedOption(), select.getOptions().get(0));
   }
 }
 /**
  * Add community
  *
  * @param community
  * @return number of communities
  */
 public int addCommunity(String community) {
   WebElement tagInput = driver.findElement(By.id("j_idt39:targetCommunities_input"));
   tagInput.sendKeys(community);
   SleepUtil.sleep(500);
   driver.findElement(By.xpath(".//*[@id='j_idt39:targetCommunities_panel']/ul/li")).click();
   return driver.findElements(By.xpath(".//*[@id='j_idt39:targetCommunities']/ul/li")).size() - 1;
 }
 /**
  * Verify that all fields with id containing selector have been filled with the correct value
  *
  * @param selector id of the field that should be filled in
  */
 public static void verifyFieldLocatedByIDIsFilledIn(
     String selector, String expectedValue, WebDriver driver) {
   String xpath = "(//input|//textarea)[contains(@id, '" + selector + "')]";
   for (WebElement field : driver.findElements(By.xpath(xpath))) {
     assertTrue(field.getAttribute("value").contains(expectedValue));
   }
 }
示例#25
0
  @Test
  public void testMemberGridViewData() throws InterruptedException {
    searchByXPathAndClick(PulseTestLocators.TopNavigation.clusterViewLinkXpath);
    testRgraphWidget();
    searchByXPathAndClick(PulseTestLocators.MemberDetailsView.gridButtonXpath);
    // get the number of rows on the grid
    List<WebElement> noOfRows =
        driver.findElements(By.xpath("//table[@id='memberRegionsList']/tbody/tr"));
    String MemberRegionName =
        driver
            .findElement(By.xpath("//table[@id='memberRegionsList']/tbody/tr[2]/td[1]"))
            .getText();
    String memberRegionName = JMXProperties.getInstance().getProperty("region.R1.name");
    Assert.assertEquals(memberRegionName, MemberRegionName);

    String MemberRegionType =
        driver
            .findElement(By.xpath("//table[@id='memberRegionsList']/tbody/tr[2]/td[2]"))
            .getText();
    String memberRegionType = JMXProperties.getInstance().getProperty("region.R1.regionType");
    Assert.assertEquals(memberRegionType, MemberRegionType);

    String MemberRegionEntryCount =
        driver
            .findElement(By.xpath("//table[@id='memberRegionsList']/tbody/tr[2]/td[3]"))
            .getText();
    String memberRegionEntryCount =
        JMXProperties.getInstance().getProperty("regionOnMember./R1.M1.entryCount");
    Assert.assertEquals(memberRegionEntryCount, MemberRegionEntryCount);
  }
 public static void main(String[] args) {
   System.setProperty("webdriver.chrome.driver", "C:/WebServerSelenium/chromedriver.exe");
   WebDriver driver = new ChromeDriver();
   driver.navigate().to(Configurations.HOMEPAGE);
   driver.manage().window().maximize();
   try {
     driver
         .findElement(By.xpath("html/body/form/table/tbody/tr/td/div/center[1]/input[1]"))
         .sendKeys("*****@*****.**");
     driver
         .findElement(By.xpath("html/body/form/table/tbody/tr/td/div/center[1]/input[2]"))
         .sendKeys("Asdfghjkl123");
     driver
         .findElement(By.xpath("html/body/form/table/tbody/tr/td/div/center[2]/input[1]"))
         .click();
     driver.findElement(By.xpath("html/body/div/div/table/tbody/tr[2]/td[1]/a")).click();
     driver.findElement(By.xpath(".//*[@id='textNomeMedico']")).sendKeys("Vincenzo");
     driver.findElement(By.xpath(".//*[@id='textCognomeMedico']")).sendKeys("Nunziata");
     driver.findElement(By.xpath("html/body/table/tbody/tr/td[1]/form/input[3]")).sendKeys("");
     driver.findElement(By.xpath("html/body/table/tbody/tr/td[1]/form/input[5]")).click();
     driver.findElement(By.xpath(".//*[@id='selectRisultati']/option")).click();
     driver.findElement(By.xpath(".//*[@id='confirmButton']/input")).click();
     List<WebElement> list =
         driver.findElements(
             By.xpath("//*[contains(text(),'" + "Richiesta inviata con successo" + "')]"));
     Assert.assertTrue(list.size() > 0, "Richiesta inviata con successo");
     System.out.println("Test Passed");
   } catch (AssertionError e) {
     System.out.println("Test Failed");
     System.out.println(e.getMessage());
   }
   driver.close();
 }
 /**
  * Add keyword
  *
  * @param keyword
  * @return number of keywords
  */
 public int addKeyword(String keyword) {
   WebElement tagInput = driver.findElement(By.id("j_idt39:messageTags_input"));
   tagInput.sendKeys(keyword);
   SleepUtil.sleep(500);
   driver.findElement(By.xpath(".//*[@id='j_idt39:messageTags_panel']/ul/li")).click();
   return driver.findElements(By.xpath(".//*[@id='j_idt39:messageTags']/ul/li")).size() - 1;
 }
  @When("^틴캐시 결제수단을 선택한다$")
  public void 틴캐시_결제수단을_선택한다() throws Throwable {
    // 라디오 버튼 사용으로 상품권 선택
    WebElement petrol =
        driver.findElement(
            By.xpath("//*[@id='common']/table/tbody/tr[2]/td/ul[2]/li[1]/span/input"));

    if (!petrol.isSelected()) petrol.click();

    assertTrue(petrol.isSelected());

    // 라디오 그룹 자동화 테스트
    List<WebElement> fuel_type = (List<WebElement>) driver.findElements(By.name("spgid"));
    for (WebElement type : fuel_type) {
      if (type.getAttribute("value").equals("gift")) {
        if (!type.isSelected()) type.click();
        assertTrue(type.isSelected());
        break;
      }
    }

    Select make = new Select(driver.findElement(By.name("spgid_gift")));
    assertFalse(make.isMultiple());
    make.selectByVisibleText("틴캐시");
    assertEquals("틴캐시", make.getFirstSelectedOption().getText());
  }
  public static void main(String[] args) {
    String baseUrl = "http://newtours.demoaut.com/";
    WebDriver driver = new FirefoxDriver();
    String underConsTitle = "Under Construction: Mercury Tours"; // Creates result string
    driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

    driver.get(baseUrl);
    List<WebElement> linkElements =
        driver.findElements(By.tagName("a")); // Creates lists from <a> tags
    String[] linkTexts = new String[linkElements.size()];
    int i = 0;

    // extract the link texts of each link element
    for (WebElement e : linkElements) {
      linkTexts[i] = e.getText();
      i++;
    }

    // test each link by looping over them
    for (String t : linkTexts) {
      driver.findElement(By.linkText(t)).click();
      if (driver.getTitle().equals(underConsTitle)) {
        System.out.println("\"" + t + "\"" + " is under construction.");
      } else {
        System.out.println(
            "\""
                + t
                + "\"" // print results to console
                + " is working.");
      }
      driver.navigate().back();
    }
    driver.quit();
  }
  /** @param args */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    WebDriver driver;
    String su = "404";
    System.setProperty("webdriver.chrome.driver", "C:/Selenium/chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("http://www.dreamdth.com");
    List<WebElement> linkElement = driver.findElements(By.tagName("a"));
    String[] linktext = new String[linkElement.size()];
    int i = 0;
    for (WebElement e : linkElement) {
      linktext[i] = e.getText();
      i++;
    }
    for (String s : linktext) {
      System.out.println(s);
      driver.findElement(By.linkText(s)).click();

      if (driver.getTitle().equals(su)) {
        System.out.println("Link InActive");
      } else {
        System.out.println("Link Active");
      }
    }
  }