本文整理匯總了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;
}
示例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) + "'");
}
示例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;
}
示例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;
}
示例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());
}
}
示例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.");
}
}
示例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;
}
}
示例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();
}
示例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);
}
}
}
示例10: setIpVersion
import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
public void setIpVersion(int i) {
Select select = new Select(ipVersionDropDown);
select.selectByIndex(i);
}
示例11: setResponseType
import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
public void setResponseType(int i) {
Select select = new Select(responseTypeDropDown);
select.selectByIndex(i);
}
示例12: selectByIndex
import org.openqa.selenium.support.ui.Select; //導入方法依賴的package包/類
public void selectByIndex(WebElement element, int value)
{
se = new Select(element);
se.selectByIndex(value);
}