当前位置: 首页>>代码示例>>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;未经允许,请勿转载。