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;
  }
示例#2
0
  public void filing_ans() {

    Select dropdown1 = new Select(driver.findElement(Question1));
    Select dropdown2 = new Select(driver.findElement(Question2));
    Select dropdown3 = new Select(driver.findElement(Question3));

    dropdown1.selectByIndex(1);
    dropdown2.selectByIndex(2);
    dropdown3.selectByIndex(3);
    //	   safesele(drop,index)
    driver.findElement(Answer1).sendKeys("test");
    driver.findElement(Answer2).sendKeys("test");
    driver.findElement(Answer3).sendKeys("test");
    driver.findElement(ContinueBtn).click();
  }
 @Test
 public void testSelect() {
   loadPage();
   Assert.assertEquals(3, select.getOptions().size());
   select.selectByIndex(0);
   Assert.assertEquals("option one", select.getFirstSelectedOption().getText());
 }
  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 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)));
   }
 }
示例#6
0
 public WebElementFacade selectByIndex(int indexValue) {
   enableHighlightingIfRequired();
   waitUntilElementAvailable();
   Select select = new Select(webElement);
   select.selectByIndex(indexValue);
   notifyScreenChange();
   return this;
 }
 @Test
 public void shouldAllowOptionsToBeSelectedByIndex() {
   WebElement selectElement = driver.findElement(By.name("select_empty_multiple"));
   Select select = new Select(selectElement);
   select.selectByIndex(1);
   WebElement firstSelected = select.getFirstSelectedOption();
   assertEquals("select_2", firstSelected.getText());
 }
  @Test
  public void shouldAllowOptionsToBeSelectedFromTheSelectElementThatIsNarrowerThanOptions() {
    driver.get(pages.selectPage);
    WebElement selectElement = driver.findElement(By.id("narrow"));
    Select select = new Select(selectElement);
    select.selectByIndex(1);
    List<WebElement> returnedOptions = select.getAllSelectedOptions();

    assertEquals(1, returnedOptions.size());
  }
示例#9
0
  private void runImport() {
    System.out.println("Importerer RFMDB dump");

    Select s = new Select(driver.findElement(new By.ByXPath("//select")));
    s.selectByIndex(2);

    driver.findElement(new By.ByXPath("//input[@value='Importer data']")).click();

    selenium.waitForFrameToLoad("content", "30000");

    captureScreenshot();
  }
示例#10
0
文件: WF_RIA.java 项目: anand853/WAFT
  public static void main(String gp[]) {

    WebDriver driver = new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get(url);
    Select dropdown;
    Util.getbtn_by_id(driver, locator).click();
    WebElement e = Util.getDropDown(driver, dLocator);
    // dropdown = new Select(driver.findElement(By.xpath(".//*[@id='type']")));
    dropdown = new Select(Util.get_by_xpath(driver, ".//*[@id='type']"));
    dropdown.selectByIndex(1);

    // Util.getDropDown(driver, dLocator).
  }
  public static void addSelection(WebDriver webDriver, String locator, String optionLocator) {

    Select select = new Select(getWebElement(webDriver, locator));

    if (optionLocator.startsWith("index=")) {
      select.selectByIndex(GetterUtil.getInteger(optionLocator.substring(6)));
    } else if (optionLocator.startsWith("label=")) {
      select.selectByVisibleText(optionLocator.substring(6));
    } else if (optionLocator.startsWith("value=")) {
      select.selectByValue(optionLocator.substring(6));
    } else {
      select.selectByVisibleText(optionLocator);
    }
  }
  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);
      }
    }
  }
  @Test(priority = 16)
  public void validateSearchResultCount() {
    LOGGER.info("STARTED: Test validateSearchResult");

    Select select = new Select(searchPage.searchPageElements.selectOnSearchPage);
    select.selectByIndex(0);

    String SEARCH_QUERY = "Table";

    searchPage.searchQuery(SEARCH_QUERY);
    String expectedMessage = searchPage.searchPageElements.resultCount.getText();
    if (searchPage.getSearchResultCount() > 0) {
      Assert.assertTrue(searchPage.getSearchResultCount() > 0, expectedMessage);
    }
    LOGGER.info("ENDED: Test validateSearchResult");
  }
示例#14
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);
   }
 }
示例#15
0
 @Test(expected = NoSuchElementException.class)
 public void shouldThrowExceptionOnSelectByIndexIfOptionDoesNotExist() {
   WebElement selectElement = driver.findElement(By.name("select_empty_multiple"));
   Select select = new Select(selectElement);
   select.selectByIndex(10);
 }
 public void selectPinType() {
   waitForElementByElement(pinCategorySelector);
   Select pinCategorySelectorDropDown = new Select(pinCategorySelector);
   pinCategorySelectorDropDown.selectByIndex(1);
   PageObjectLogging.log("selectPinType", "Pin type was choosed", true, driver);
 }
 protected void dropdownSelect(String locator, int data) {
   Select dropdown = new Select(driver.findElement(By.name(locator)));
   dropdown.selectByIndex(data);
 }
  @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");
      }
    }
  }
 /** Select the value from a dropdown list by its index */
 public void selectDropDownByIndex(MethodParameters model) {
   MainTestNG.LOGGER.info("inside selectDropDownByIndex");
   Select sel = new Select(model.getElement().get(0));
   sel.selectByIndex(Integer.parseInt(model.getData()));
 }
 public void selectByIndex() {
   select.selectByIndex(Integer.parseInt(getData()));
 }