當前位置: 首頁>>代碼示例>>Java>>正文


Java Select.selectByIndex方法代碼示例

本文整理匯總了Java中org.openqa.selenium.support.ui.Select.selectByIndex方法的典型用法代碼示例。如果您正苦於以下問題:Java Select.selectByIndex方法的具體用法?Java Select.selectByIndex怎麽用?Java Select.selectByIndex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openqa.selenium.support.ui.Select的用法示例。


在下文中一共展示了Select.selectByIndex方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: randomSelect

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
@Override
public WebElement randomSelect(Element ele)
{
	Select select = createSelect(ele);
	if(select != null)
	{
		List<WebElement> options = select.getOptions();
		if(CollectionUtils.isNotEmpty(options))
		{
			int count = options.size();
			int index = RandomUtils.nextInt(count);
			index = (index == 0 ? 1 : index); //通常第一個選項都是無效的選項

			select.selectByIndex(index);
			
			return options.get(index);
		}
	}
	
	return null;
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:22,代碼來源:SeleniumSelect.java

示例2: selectOptionByIndex

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
/**
 * Select option by option index.
 * 
 * @param locator
 *            - element locator
 * @param replacement
 *            - if element contains dynamic part, i.e. '$value' in locator
 *            part, then '$value' part will be replaced by replacement value
 * @param optionIndex
 *            - index of dropdown option
 * @throws PropertyNotFoundException
 *             - throw this exception when declared locator is not found in
 *             object repository
 * @throws InvalidLocatorStrategyException
 *             - throw this exception when locator strategy is wrong. Valid
 *             locator strategies are 'ID', 'XPATH', 'NAME', 'CSS_SELECTOR',
 *             'CLASS_NAME', 'LINK_TEXT', 'PARTIAL_LINK_TEXT' and 'TAG_NAME'
 */
public void selectOptionByIndex(String locator, String replacement, int optionIndex)
        throws PropertyNotFoundException, InvalidLocatorStrategyException
{
    if (replacement != null)
    {
        if (locator.contains("$value"))
        {
            locator = locator.replace("$value", replacement);
        }
    }

    element = ElementFinder.findElement(driver, locator);

    Select dropdown = new Select(element);
    dropdown.selectByIndex(optionIndex);

    LOGGER.info("Successfully selected option with index " + optionIndex + "' from element '" + locator
            + "' with locator value '" + props.getProperty(locator) + "'");
}
 
開發者ID:pradeeptaswain,項目名稱:oldmonk,代碼行數:38,代碼來源:BasePage.java

示例3: selectByIndex

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
@Override
public boolean selectByIndex(Element element, int index)
{
	Select select = createSelect(element);
	if(select != null)
	{
		select.selectByIndex(index);
		return true;
	}

	return false;
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:13,代碼來源:SeleniumSelect.java

示例4: clickDropdownOptionAndIndex

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
@Override
public boolean clickDropdownOptionAndIndex(WebElement w, String... args) throws Exception{
	boolean result = false;
	String d = args[0];
	try{
		Select s = new Select(w);
		s.selectByIndex(Integer.parseInt(d) - 1);
		result = true;
	}catch(Exception e){
		e.printStackTrace();
		result = false;
	}
	Assert.assertTrue(result, w.toString() + " - select drop down item with index = " + d);
	return result;
}
 
開發者ID:saiscode,項目名稱:kheera,代碼行數:16,代碼來源:AbstractPage.java

示例5: setDropDownValue

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
private void setDropDownValue(PageElement element, String text) throws TechnicalException, FailureException {
    WebElement select = Context.waitUntil(ExpectedConditions.elementToBeClickable(Utilities.getLocator(element)));
    Select dropDown = new Select(select);
    int index = NameUtilities.findOptionByIgnoreCaseText(text, dropDown);
    if (index != -1) {
        dropDown.selectByIndex(index);
    } else {
        new Result.Failure<>(text, Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_VALUE_NOT_AVAILABLE_IN_THE_LIST), element, element.getPage().getApplication()), false,
                element.getPage().getCallBack());
    }

}
 
開發者ID:NoraUi,項目名稱:NoraUi,代碼行數:13,代碼來源:Step.java

示例6: run

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
@Override
public void run() {
    super.run();

    By locator = this.readLocatorArgument("locator");
    String optionValue = this.readStringArgument("optionValue", null);
    String optionText = this.readStringArgument("optionText", null);
    Integer optionNumber = this.readIntArgument("optionNumber", null);

    this.waitForAsyncCallsToFinish();

    Select dropdownElement = new Select(this.getElement(locator));

    if (optionValue != null) {
        dropdownElement.selectByValue(optionValue);
    } else if (optionText != null) {
        dropdownElement.selectByVisibleText(optionText);
    } else if (optionNumber != null) {
        dropdownElement.selectByIndex(optionNumber - 1);
    } else {
        throw new RuntimeException(
                "You must identify the option you want to select from the "
                + "list by providing one of the following arguments: "
                + "optionValue, optionText or optionIndex.");
    }

}
 
開發者ID:mcdcorp,項目名稱:opentest,代碼行數:28,代碼來源:SelectListOption.java

示例7: selectAll

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
private void selectAll(SelectType selectType) {
    switch (selectType) {
        case Select:
            Select select = new Select(Element);
            for (int i = 0; i < select.getOptions().size(); i++) {
                select.selectByIndex(i);
            }
            break;
        case DeSelect:
            new Select(Element).deselectAll();
            break;
    }

}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:15,代碼來源:Dropdown.java

示例8: getOppositeUser

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
private static String getOppositeUser(String transactionNo) {
	// ��ȡ�ؼ��ֶ�Ӧ��������
	WebElement keywordInput = driver.findElement(By.id("J-keyword"));
	keywordInput.clear();
	keywordInput.sendKeys(transactionNo);
	WebElement keywordSelect = driver.findElement(By.id("keyword"));
	List<WebElement> options = keywordSelect.findElements(By.tagName("option"));
	// until������ʾֱ���ɵ��ٵ�
	// WebElement selectElement = wait.until(ExpectedConditions
	// .visibilityOfElementLocated(By.id("keyword")));
	// ��Ҫִ��JavaScript��䣬����ǿתdriver
	JavascriptExecutor js = (JavascriptExecutor) driver;
	// Ҳ������ô��setAttribute("style","");
	js.executeScript("document.getElementById('keyword').style.display='list-item';");
	js.executeScript("document.getElementById('keyword').removeAttribute('smartracker');");
	js.executeScript("document.getElementById('keyword').options[1].selected = true;");
	js.executeScript("document.getElementById('J-select-range').style.display='list-item';");
	// ���ý���ʱ��ѡ��
	Select selectTime = new Select(driver.findElement(By.id("J-select-range")));
	selectTime.selectByIndex(3);// ѡ�е������������
	System.out.println("selectTime.isMultiple() : " + selectTime.isMultiple());
	// ���ùؼ���ѡ��
	Select selectKeyword = new Select(driver.findElement(By.id("keyword")));
	// selectKeyword.selectByValue("bizInNo");//�˴���value��д<option>��ǩ�е�valueֵ
	selectKeyword.selectByIndex(1);// ѡ�е��ǽ��׺�
	System.out.println("selectKeyword.isMultiple() : " + selectKeyword.isMultiple());
	WebElement queryButton = driver.findElement(By.id("J-set-query-form"));// �õ�������ť
	// ���������ť
	queryButton.submit();
	WebElement tr = driver.findElement(By.id("J-item-1"));// �Ȼ�ȡtr
	WebElement td = tr.findElement(By.xpath("//*[@id=\"J-item-1\"]/td[5]/p[1]"));
	return td.getText();
}
 
開發者ID:qwl-nju,項目名稱:AlipayAuto,代碼行數:34,代碼來源:AlipayAuto.java

示例9: selectOptionByIndex

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
/**
 * Select option by index.
 *
 * @param element the element
 * @param indexNo the index no
 */
public static void selectOptionByIndex(WebElement element, int indexNo) {
	if (element != null) {
		Select option = new Select(element);
		if (option != null) {
			option.selectByIndex(indexNo);
		}
	}
}
 
開發者ID:anilpandeykiet,項目名稱:POM_HYBRID_FRAMEOWRK,代碼行數:15,代碼來源:WebDropdown.java

示例10: setIpVersion

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
public void setIpVersion(int i) {
    Select select = new Select(ipVersionDropDown);
    select.selectByIndex(i);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:5,代碼來源:TestSuiteAddPage.java

示例11: setResponseType

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
public void setResponseType(int i) {
    Select select = new Select(responseTypeDropDown);
    select.selectByIndex(i);
}
 
開發者ID:Comcast,項目名稱:redirector,代碼行數:5,代碼來源:TestSuiteAddPage.java

示例12: selectByIndex

import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
public void selectByIndex(WebElement element, int value)
{
	se = new Select(element);
	se.selectByIndex(value);
}
 
開發者ID:GladsonAntony,項目名稱:WebAutomation_AllureParallel,代碼行數:6,代碼來源:BaseMethod.java


注:本文中的org.openqa.selenium.support.ui.Select.selectByIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。