public static WebElement prospectList_fillFormList(WebDriver driver, String emailID)
      throws Exception {

    // Wait for the Add New Prospect form to load
    WebDriverWait wait = new WebDriverWait(driver, 60);
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='email']")));
    Log.info("Waiting for Prospect->List->AddProspect New form");

    // Fill out Add New Prospect Form

    element = driver.findElement(By.xpath("//input[@id='email']"));
    element.sendKeys(emailID);

    Log.info("--- Filling AddProspect form ---- ");

    // Select a campaign option
    Log.info("Filling AddProspect form Selecting Campaign");

    Select campaignDropdown =
        new Select(driver.findElement(By.xpath("//select[@id='campaign_id']")));
    List<WebElement> campaignWeblist = campaignDropdown.getOptions();
    int cCnt = campaignWeblist.size();
    Log.info("Total campaignWeblist is " + cCnt);

    Random cnum = new Random();
    int cSelect = cnum.nextInt(cCnt);
    campaignDropdown.selectByIndex(cSelect);
    Log.info("Selected campaignWeblist " + cSelect);

    Thread.sleep(10);
    // Select a profile option

    Select profileDropdown = new Select(driver.findElement(By.xpath("//select[@id='profile_id']")));
    List<WebElement> profileWeblist = profileDropdown.getOptions();
    int pCnt = profileWeblist.size();
    Log.info("Total profileWeblist is " + pCnt);

    Random pnum = new Random();
    int pSelect = pnum.nextInt(pCnt);
    profileDropdown.selectByIndex(pSelect);
    Log.info("Selected profileWeblist " + pSelect);
    Thread.sleep(10);

    // Clear and Enter a Score Value
    element = driver.findElement(By.xpath("//input[@id='score']"));
    element.clear();

    element = driver.findElement(By.xpath("//input[@id='score']"));
    element.sendKeys(Constant.scoreVal);
    ;
    Log.info("Enter Score Value " + Constant.scoreVal);

    // wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h1[contains(.,'*****@*****.**')]")));
    return element;
  }
  protected static void selectByRegexpValue(
      WebDriver webDriver, String selectLocator, String regexp) {

    WebElement webElement = getWebElement(webDriver, selectLocator);

    Select select = new Select(webElement);

    List<WebElement> optionWebElements = select.getOptions();

    Pattern pattern = Pattern.compile(regexp);

    int index = -1;

    for (WebElement optionWebElement : optionWebElements) {
      String optionWebElementValue = optionWebElement.getAttribute("value");

      Matcher matcher = pattern.matcher(optionWebElementValue);

      if (matcher.matches()) {
        index = optionWebElements.indexOf(optionWebElement);

        break;
      }
    }

    select.selectByIndex(index);
  }
 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));
   }
 }
 @Test
 public void testSelect() {
   loadPage();
   Assert.assertEquals(3, select.getOptions().size());
   select.selectByIndex(0);
   Assert.assertEquals("option one", select.getFirstSelectedOption().getText());
 }
예제 #5
0
 public boolean isTextEqualInDropdown(Supplier<By> by, String text) {
   final Element element = untilFound(by);
   Select dropdown = new Select(element);
   return dropdown
       .getOptions()
       .parallelStream()
       .anyMatch(opt -> opt.getText().equals(text.trim()));
 }
 private static void updateSelectFieldtoDefault(String selector, WebDriver driver) {
   String xpath = "(//select)[contains(@class, '" + selector + "')]";
   for (WebElement element : driver.findElements(By.xpath(xpath))) {
     Select select = new Select(element);
     select.selectByIndex(0);
     new WebDriverWait(driver, 10).until(elementToBeSelected(select.getOptions().get(0)));
   }
 }
예제 #7
0
 public List<Integer> getAllSelectedIndices(Supplier<By> by) {
   Select select = new Select(findElement(by));
   List<WebElement> options = select.getOptions();
   return select
       .getAllSelectedOptions()
       .stream()
       .map(options::indexOf)
       .collect(Collectors.toList());
 }
예제 #8
0
 public double getWindowsPrice() throws Exception {
   WebElement windowsPrice = driver.findElement(By.id("option_820_zg-cs-operatingsystem"));
   Select select = new Select(windowsPrice);
   List<WebElement> options = select.getOptions();
   for (WebElement option : options) {
     if (option.getText().contains("Windows")) {
       return this.extractNumber(option.getText(), true);
     }
   }
   throw new Exception("Windows not found");
 }
예제 #9
0
 public Integer getFirstSelectedIndex(Supplier<By> by) {
   try {
     Select select = new Select(findElement(by));
     List<WebElement> options = select.getOptions();
     if (!options.isEmpty()) {
       return options.indexOf(select.getFirstSelectedOption());
     }
     return null;
   } catch (NoSuchElementException e) {
     return null;
   }
 }
예제 #10
0
 public void selectFirstElementInTheDropDown(Supplier<By> by) {
   final Element element = untilFound(by);
   Select dropdown = new Select(element);
   String textOption =
       dropdown
           .getOptions()
           .parallelStream()
           .filter(el -> !el.getText().equals(""))
           .findFirst()
           .get()
           .getText();
   dropdown.selectByVisibleText(textOption);
 }
예제 #11
0
 public void selectByText(Supplier<By> by, String select) {
   final Element element = untilFound(by);
   Select dropdown = new Select(element);
   String textOption =
       dropdown
           .getOptions()
           .parallelStream()
           .filter(opt -> opt.getText().contains(select))
           .findFirst()
           .get()
           .getText();
   dropdown.selectByVisibleText(textOption);
 }
  public static void select(WebDriver webDriver, String selectLocator, String optionLocator) {

    WebElement webElement = getWebElement(webDriver, selectLocator);

    Select select = new Select(webElement);

    String label = optionLocator;

    if (optionLocator.startsWith("index=")) {
      String indexString = optionLocator.substring(6);

      int index = GetterUtil.getInteger(indexString);

      select.selectByIndex(index - 1);
    } else if (optionLocator.startsWith("value=")) {
      String value = optionLocator.substring(6);

      if (value.startsWith("regexp:")) {
        String regexp = value.substring(7);

        selectByRegexpValue(webDriver, selectLocator, regexp);
      } else {
        List<WebElement> optionWebElements = select.getOptions();

        for (WebElement optionWebElement : optionWebElements) {
          String optionWebElementValue = optionWebElement.getAttribute("value");

          if (optionWebElementValue.equals(value)) {
            label = optionWebElementValue;

            break;
          }
        }

        select.selectByValue(label);
      }
    } else {
      if (optionLocator.startsWith("label=")) {
        label = optionLocator.substring(6);
      }

      if (label.startsWith("regexp:")) {
        String regexp = label.substring(7);

        selectByRegexpText(webDriver, selectLocator, regexp);
      } else {
        select.selectByVisibleText(label);
      }
    }
  }
예제 #13
0
 /**
  * @param locator Path to drop-down selector
  * @param index Index number to be selected
  */
 protected void selectByIndex(String locator, int index) {
   try {
     Select select = new Select(driver.findElement(getLocator(locator)));
     if (select.getOptions().size() < index) {
       log.error("SELECTED BY INDEX does not exist: " + index);
     } else {
       select.selectByIndex(index);
       log.info("SELECTED BY INDEX: " + index + "from the: " + locator);
     }
   } catch (Throwable e) {
     log.error("SELECTED BY INDEX element not found: " + locator);
     log.debug(e);
     captureScreen(
         getBrowserDetails(driver) + "/operationErrors/select/byIndex" + locator, driver);
   }
 }
예제 #14
0
  @Test
  public void shouldReturnAllOptionsWhenAsked() {
    WebElement selectElement = driver.findElement(By.name("selectomatic"));
    Select select = new Select(selectElement);
    List<WebElement> returnedOptions = select.getOptions();

    assertEquals(4, returnedOptions.size());

    String one = returnedOptions.get(0).getText();
    assertEquals("One", one);

    String two = returnedOptions.get(1).getText();
    assertEquals("Two", two);

    String three = returnedOptions.get(2).getText();
    assertEquals("Four", three);

    String four = returnedOptions.get(3).getText();
    assertEquals("Still learning how to count, apparently", four);
  }
예제 #15
0
  public static void main(String[] args) throws Exception {

    FirefoxDriver driver = new FirefoxDriver();

    driver.manage().window().maximize();

    driver.get("http://www.facebook.com");

    System.out.println(driver.getTitle());

    // get month dropdown
    WebElement month_dropdown = driver.findElementById("month");

    // Create object of Select class
    Select month = new Select(month_dropdown);

    // Get all values from dropdown
    List<WebElement> month_values = month.getOptions();

    // Get the count
    int dropdown_count = month_values.size();

    System.out.println("Total count is >>>>" + dropdown_count);

    // run a loop that will give all values
    for (int i = 0; i < dropdown_count; i++) {

      // get web element from list
      WebElement month_value = month_values.get(i);

      // get the text
      String month_actual_text = month_value.getText();

      // print the values
      System.out.println(month_actual_text);
    }

    // driver.quit();

  }
예제 #16
0
  /**
   * @param data
   * @param inputValues
   * @return true/false
   *     <pre>{@code
   * Creates an TMC Employee based oon the inputValues supplied from
   * Excel Data
   *
   * }</pre>
   */
  protected Map<String, Object> AddEmployee(SuiteConfig data, Map<String, String> inputValues) {
    WebDriver driver = registerAndLogin(data, false);
    boolean state = false;
    Map<String, Object> values = new HashMap<String, Object>();
    Map<String, FluentWebElement> clientsMap = new HashMap<String, FluentWebElement>();
    try {
      FluentWebDriver fluent = new FluentWebDriver(driver);
      takeScreenShots("/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);
      log.info("Input Values : " + inputValues);
      Thread.sleep(8000);
      driver.switchTo().frame("Table");
      // Find an Employee
      FluentWebElements clients =
          fluent.links(
              By.xpath(
                  "contains(.,'"
                      + inputValues.get("client")
                      + "')")); // *[@id="ClientListTable"]/tbody/tr[287]/td[3]/span[1]/a
      for (FluentWebElement client : clients) {
        if (client.isDisplayed().value() && client.isEnabled().value()) {
          clientsMap.put(client.getText().toString(), client);
        }
      }
      FluentWebElement clientClick = clientsMap.get(inputValues.get("client"));
      clientClick.click();
      Thread.sleep(3000);
      driver.switchTo().frame("Table");
      FluentWebElement group =
          fluent.link(By.xpath("contains(.,'" + inputValues.get("group") + "')"));
      if (group.isDisplayed().value() && group.isEnabled().value()) {
        group.click();
        takeScreenShots("/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);
        Thread.sleep(4000);
        if (data.getProject().equals("TMC")) {
          if (getFrameElement(driver, "Menu") != null) {
            driver.switchTo().frame(getFrameElement(driver, "Menu"));
            Thread.sleep(3000);
            Select select = new Select(driver.findElement(By.name("Maintenance")));
            select.selectByVisibleText("Employee Setup");
            Robot robot = new Robot();

            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);

            Thread.sleep(500);
          }
          if (getFrameElement(driver, "Navigation") != null) {
            // Add an Employee
            driver.switchTo().frame(getFrameElement(driver, "Navigation"));
            takeScreenShots(
                "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);
            driver.findElement(By.id("AddEmpButton")).click();
          }
          for (String winHandle : driver.getWindowHandles()) {
            driver.switchTo().window(winHandle);
            log.info("winHandle: " + winHandle);
          }
          Thread.sleep(3000);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);
          Thread.sleep(2000);
          driver.findElement(By.name("EmplSSN")).sendKeys(inputValues.get("ssn"));
          getInputElement(driver, "value", "Next >>").click();
          Thread.sleep(500);
          for (String winHandle : driver.getWindowHandles()) {
            driver.switchTo().window(winHandle);
            log.info("winHandle: " + winHandle);
          }
          Thread.sleep(3000);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);
          if (getFrameElement(driver, "Main") != null) {
            // Add an Employee
            driver.switchTo().frame(getFrameElement(driver, "Main"));
            driver.findElement(By.id("LastName")).sendKeys(inputValues.get("lastName"));
            driver.findElement(By.id("FirstName")).sendKeys(inputValues.get("firstName"));

            Select select = new Select(driver.findElement(By.name("PayType")));
            select.selectByVisibleText(inputValues.get("payType"));
            Robot robot = new Robot();

            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
            Thread.sleep(500);

            Select select1 = new Select(driver.findElement(By.name("Status")));
            select1.selectByVisibleText(inputValues.get("status"));
            Robot robot1 = new Robot();

            robot1.keyPress(KeyEvent.VK_ENTER);
            robot1.keyRelease(KeyEvent.VK_ENTER);

            Thread.sleep(1500);
            takeScreenShots(
                "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);

            driver.findElement(By.id("sitesDepts")).click();
            Thread.sleep(1500);
            takeScreenShots(
                "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);
            Select select2 = new Select(driver.findElement(By.name("SiteDeptTemplate")));
            String optionText = "";
            List<WebElement> options = select2.getOptions();
            for (WebElement element : options) {
              if (element.getText() != null
                  && !element.getText().isEmpty()
                  && !element.getText().equals("Select Template")) {
                optionText = element.getText();
                break;
              }
            }
            select2.selectByVisibleText(optionText);
            Robot robot2 = new Robot();

            robot2.keyPress(KeyEvent.VK_ENTER);
            robot2.keyRelease(KeyEvent.VK_ENTER);
            Thread.sleep(5000);

            Select select3 = new Select(driver.findElement(By.name("PrimaryDept")));
            String optionText1 = "";
            List<WebElement> options1 = select3.getOptions();
            for (WebElement element : options1) {
              if (element.getText() != null
                  && !element.getText().isEmpty()
                  && !element.getText().equals("Select Template")) {
                optionText1 = element.getText();
                break;
              }
            }
            select3.selectByVisibleText(optionText1);
            Robot robot3 = new Robot();
            robot3.keyPress(KeyEvent.VK_ENTER);
            robot3.keyRelease(KeyEvent.VK_ENTER);
            Thread.sleep(1500);

            Select select4 = new Select(driver.findElement(By.name("PrimarySite")));
            String optionText2 = "";
            List<WebElement> options2 = select4.getOptions();
            for (WebElement element : options2) {
              if (element.getText() != null
                  && !element.getText().isEmpty()
                  && !element.getText().equals("Select Template")) {
                optionText2 = element.getText();
                break;
              }
            }
            select4.selectByVisibleText(optionText2);
            Robot robot4 = new Robot();
            robot4.keyPress(KeyEvent.VK_ENTER);
            robot4.keyRelease(KeyEvent.VK_ENTER);
            Thread.sleep(500);
            takeScreenShots("/AddEmployee/addAnEmployee", data.getGroup(), driver);
            driver.findElement(By.id("Remove2")).click();
            Thread.sleep(100);
            driver.findElement(By.id("Remove3")).click();
            Thread.sleep(100);
            driver.findElement(By.id("Remove4")).click();
            Thread.sleep(100);
            driver.findElement(By.id("Remove5")).click();
            takeScreenShots("/AddEmployee/addAnEmployee", data.getGroup(), driver);
          }
          Thread.sleep(1000);
          for (String winHandle : driver.getWindowHandles()) {
            driver.switchTo().window(winHandle);
            log.info("winHandle: " + winHandle);
          }
          Thread.sleep(1000);
          takeScreenShots("/AddEmployee/addAnEmployee", data.getGroup(), driver);
          if (getFrameElement(driver, "Navigation") != null) {
            driver.switchTo().frame(getFrameElement(driver, "Navigation"));
            driver.findElement(By.name("save")).click();
            Thread.sleep(1000);
          }
          takeScreenShots("/AddEmployee/addAnEmployee", data.getGroup(), driver);
          Thread.sleep(1000);
          driver.quit();
        } else {
          driver.switchTo().frame(getFrameElement(driver, "Menu"));
          Thread.sleep(3000);
          FluentSelect select = fluent.select(By.name("Maintenance"));
          select.selectByVisibleText("Administration");
          Robot robot = new Robot();

          robot.keyPress(KeyEvent.VK_ENTER);
          robot.keyRelease(KeyEvent.VK_ENTER);

          Thread.sleep(500);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);

          for (String winHandle : driver.getWindowHandles()) {
            driver.switchTo().window(winHandle);
            log.info("winHandle: " + winHandle);
          }
          Thread.sleep(3000);
          fluent.input(By.id("btnDecline")).click();

          Thread.sleep(3000);
          for (String winHandle : driver.getWindowHandles()) {
            driver.switchTo().window(winHandle);
            log.info("winHandle: " + winHandle);
          }
          Thread.sleep(3000);

          driver.switchTo().frame(getFrameElement(driver, "Table"));
          fluent.link(By.xpath("contains(.,'" + inputValues.get("group") + " Setup')")).click();
          Thread.sleep(3000);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);

          // driver.switchTo().frame("Table");
          driver.findElement(By.xpath("/html/body/form/table[2]/tbody/tr/td/span/a")).click();
          Thread.sleep(3000);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);

          if (inputValues.get("client").equals("MANPOWER GROUP")
              || inputValues.get("client").equals("CANADA")) {
            fluent.link(By.xpath("contains(.,'Non-Agency Employees')")).click();
            Thread.sleep(1500);
          }
          // driver.switchTo().frame("Table");
          fluent.input(By.className("smallbold")).click();
          Thread.sleep(3000);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);

          // driver.switchTo().frame(getFrameElement(driver,
          // "Table"));

          fluent.input(By.name("SSN")).sendKeys(inputValues.get("lastSSN"));
          Thread.sleep(1500);
          fluent.input(By.name("FirstName")).sendKeys(inputValues.get("firstName"));
          Thread.sleep(1500);
          fluent.input(By.name("LastName")).sendKeys(inputValues.get("lastName"));
          Thread.sleep(1500);
          fluent.input(By.name("EmpEmail")).sendKeys(inputValues.get("empEmail"));
          Thread.sleep(1500);
          fluent.input(By.name("FileNo")).sendKeys(inputValues.get("empId"));
          Thread.sleep(1500);
          FluentSelect timeEntry = fluent.select(By.name("WTE_TimeEntry"));
          timeEntry.selectByVisibleText("Spreadsheet w/Projects");
          Robot robot1 = new Robot();
          robot1.keyPress(KeyEvent.VK_ENTER);
          robot1.keyRelease(KeyEvent.VK_ENTER);
          Thread.sleep(500);
          Thread.sleep(1500);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);

          FluentSelect clientSel = fluent.select(By.name("SiteNo"));
          clientSel.selectByVisibleText(inputValues.get("site"));

          Robot robot2 = new Robot();
          robot2.keyPress(KeyEvent.VK_ENTER);
          robot2.keyRelease(KeyEvent.VK_ENTER);
          Thread.sleep(500);
          Thread.sleep(1500);

          fluent.input(By.name("JobDesc")).sendKeys("Harmony Responsive Tester");
          Thread.sleep(1500);
          fluent.input(By.name("AssignmentNo")).sendKeys("98723425");
          Thread.sleep(1500);
          fluent.input(By.name("AssignmentStart")).sendKeys("01/01/2015");
          Thread.sleep(1500);
          fluent.input(By.name("AssignmentEnd")).sendKeys("12/31/2018");
          Thread.sleep(1500);
          fluent.input(By.name("BillRate")).sendKeys("18.00");
          Thread.sleep(1500);
          fluent.input(By.name("PayRate")).sendKeys("16.00");
          Thread.sleep(1500);
          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);

          FluentSelect stateSel = fluent.select(By.name("workState"));
          stateSel.selectByVisibleText("GEORGIA");

          Robot robot3 = new Robot();
          robot3.keyPress(KeyEvent.VK_ENTER);
          robot3.keyRelease(KeyEvent.VK_ENTER);
          Thread.sleep(500);
          Thread.sleep(1500);

          fluent.input(By.name("ApproverFirstName")).sendKeys(inputValues.get("apprFirstName"));
          Thread.sleep(1500);
          fluent.input(By.name("ApproverLastName")).sendKeys(inputValues.get("apprLastName"));
          Thread.sleep(1500);
          fluent.input(By.name("ApproverEmail")).sendKeys(inputValues.get("apprEmail"));
          Thread.sleep(1500);

          takeScreenShots(
              "/" + data.getScript() + "/TimeEntry/screenshot", data.getGroup(), driver);
          Thread.sleep(1500);
          getInputElement(driver, "value", "Save Employee").click();
          Thread.sleep(12000);
        }
        state = true;
        String currentUrl = driver.getCurrentUrl();
        if (!currentUrl.contains("qa2-www.mypeoplenet.com")) {
          Map<String, String> employeeData = checkForEmployee(data, inputValues);
          if (employeeData != null && !employeeData.isEmpty()) {
            inputValues.put("userId", employeeData.get("userId"));
            inputValues.put("recordId", employeeData.get("recordId"));
            inputValues.put("password", employeeData.get("password"));
          }
        }
        values.put("status", state);
        values.put("driver", driver);
      } else {
        driver.quit();
      }

    } catch (Exception e) {
      takeScreenShots("/" + data.getScript() + "/ERROR/screenshot", data.getGroup(), driver);
      driver.quit();
      e.printStackTrace();
    }
    return values;
  }
예제 #17
0
 public boolean isTextPresentInTheDropdown(Supplier<By> by, String text) {
   final Element element = untilFound(by);
   Select dropdown = new Select(element);
   return dropdown.getOptions().parallelStream().anyMatch(opt -> opt.getText().contains(text));
 }
  @Override
  public void select(String selectLocator, String optionLocator) {
    WebElement webElement = getWebElement(selectLocator);

    Select select = new Select(webElement);

    List<WebElement> options = select.getOptions();

    String label = optionLocator;

    int index = -1;

    if (optionLocator.startsWith("index=")) {
      String indexString = optionLocator.substring(6);

      index = GetterUtil.getInteger(indexString);
    } else if (optionLocator.startsWith("label=")) {
      label = optionLocator.substring(6);
    } else if (optionLocator.startsWith("value=")) {
      String value = optionLocator.substring(6);

      if (value.startsWith("regexp:")) {
        String regexp = value.substring(7);

        Pattern pattern = Pattern.compile(regexp);

        for (WebElement option : options) {
          String optionValue = option.getAttribute("value");

          Matcher matcher = pattern.matcher(optionValue);

          if (matcher.matches()) {
            index = options.indexOf(option);

            break;
          }
        }
      } else {
        for (WebElement option : options) {
          String optionValue = option.getAttribute("value");

          if (optionValue.equals(value)) {
            label = option.getText();

            break;
          }
        }
      }
    }

    if (index > -1) {
      select.selectByIndex(index);
    } else {
      keyPress(selectLocator, "\\36");

      if (!label.equals(getSelectedLabel(selectLocator))) {
        webElement.sendKeys(label);

        keyPress(selectLocator, "\\13");
      }
    }
  }