本文整理汇总了Java中org.openqa.selenium.support.ui.Select类的典型用法代码示例。如果您正苦于以下问题:Java Select类的具体用法?Java Select怎么用?Java Select使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Select类属于org.openqa.selenium.support.ui包,在下文中一共展示了Select类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateValue
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
/**
* Update the specified element with the indicated value
*
* @param element target element (input, select)
* @param value desired value
* @return 'true' if element value changed; otherwise 'false'
*/
public static boolean updateValue(WebElement element, String value) {
Objects.requireNonNull(element, "[element] must be non-null");
String tagName = element.getTagName().toLowerCase();
if ("input".equals(tagName)) {
if ("checkbox".equals(element.getAttribute("type"))) {
return updateValue(element, Boolean.parseBoolean(value));
} else if (!valueEquals(element, value)) {
if (value == null) {
element.clear();
} else {
WebDriverUtils.getExecutor(element).executeScript("arguments[0].select();", element);
element.sendKeys(value);
}
return true;
}
} else if ("select".equals(tagName) && !valueEquals(element, value)) {
new Select(element).selectByValue(value);
return true;
}
return false;
}
示例2: etreSelectionne
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
@Override
public void etreSelectionne(String type, String selector, String valeur) {
WebElement elem = this.findElement(BySelec.get(type, selector));
String tagName = elem.getTagName();
if (tagName.equals("select")) {
Select listProfile = new Select(elem);
if (!listProfile.getFirstSelectedOption().getText().equals(valeur)) {
Assert.fail("la valeur de l'élément ne correspond pas à la valeur " + valeur + "!");
}
} else {
WebElement item = elem.findElement(By.cssSelector("li > div > div:first-child()"));
if (!item.getText().equals(valeur)) {
Assert.fail("la valeur de l'élément ne correspond pas à la valeur " + valeur + "!");
}
}
}
示例3: 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;
}
示例4: SelectByVisibleText_BootStrap
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
public static void SelectByVisibleText_BootStrap( WebDriver driver, By elementById, String visibleOptionText )
{
try
{
String elementId = elementById.toString().split( ":" )[ 1 ].trim();
String js = String.format( "document.getElementById('%s').removeAttribute('class');", elementId );
( ( JavascriptExecutor ) driver ).executeScript( js );
//( ( JavascriptExecutor ) driver ).executeScript( String.format( "document.getElementById('%s').style.display='block';", elementId ) );
String cssSelector = String.format( "select#%s", elementId );
Select selectObject = new Select( driver.findElement( By.cssSelector( cssSelector ) ) );
selectObject.selectByVisibleText( visibleOptionText );
} catch( Exception e )
{
throw new WebDriverException("Some error occured while Selecting option", e);
}
}
示例5: setValue
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
/**
* select a value
*
* @param value the value to select
*/
@Override
@PublicAtsApi
public void setValue(
String value ) {
new RealHtmlElementState(this).waitToBecomeExisting();
try {
WebElement element = RealHtmlElementLocator.findElement(this);
Select select = new Select(element);
select.selectByVisibleText(value);
} catch (NoSuchElementException nsee) {
throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
+ this.toString() + ")");
}
UiEngineUtilities.sleep();
}
示例6: unsetValue
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
/**
* unselect a value
*
* @param value the value to unselect
*/
@Override
@PublicAtsApi
public void unsetValue(
String value ) {
new RealHtmlElementState(this).waitToBecomeExisting();
WebElement element = RealHtmlElementLocator.findElement(this);
Select select = new Select(element);
// select.deselectByVisibleText( value ); // this method doesn't throw an exception if the option doesn't exist
for (WebElement option : select.getOptions()) {
if (option.getText().equals(value)) {
if (option.isSelected()) {
option.click();
UiEngineUtilities.sleep();
}
return;
}
}
throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
+ this.toString() + ")");
}
示例7: getValues
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
/**
* @return the selected values
*/
@Override
@PublicAtsApi
public String[] getValues() {
new RealHtmlElementState(this).waitToBecomeExisting();
WebElement element = RealHtmlElementLocator.findElement(this);
Select select = new Select(element);
List<WebElement> selectedOptions = select.getAllSelectedOptions();
String[] result = new String[selectedOptions.size()];
int i = 0;
for (WebElement selectedOption : selectedOptions) {
result[i++] = selectedOption.getText();
}
return result;
}
示例8: setValue
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
/**
* set the single selection value
*
* @param value the value to select
*/
@Override
@PublicAtsApi
public void setValue(
String value ) {
new RealHtmlElementState(this).waitToBecomeExisting();
try {
WebElement element = RealHtmlElementLocator.findElement(this);
Select select = new Select(element);
select.selectByVisibleText(value);
} catch (NoSuchElementException nsee) {
throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
+ this.toString() + ")");
}
UiEngineUtilities.sleep();
}
示例9: getAllPossibleValues
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
/**
* @return a list with all possible selection values
*/
@Override
@PublicAtsApi
public List<String> getAllPossibleValues() {
List<String> values = new ArrayList<String>();
new RealHtmlElementState(this).waitToBecomeExisting();
WebElement element = RealHtmlElementLocator.findElement(this);
Select select = new Select(element);
Iterator<WebElement> iterator = select.getOptions().iterator();
if (!select.getAllSelectedOptions().isEmpty()) {
while (iterator.hasNext()) {
values.add(iterator.next().getText());
}
return values;
}
throw new SeleniumOperationException("There is no selectable 'option' in " + this.toString());
}
示例10: createEvent
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
public HomePageObject createEvent(String title, String country, String location, String description){
setText("createEventForm:title",title);
setText("createEventForm:location",location);
setText("createEventForm:description",description);
new Select(driver.findElement(By.id("createEventForm:country"))).selectByVisibleText(country);
driver.findElement(By.id("createEventForm:createButton")).click();
waitForPageToLoad();
if(isOnPage()){
return null;
} else {
return new HomePageObject(driver);
}
}
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:17,代码来源:CreateEventPageObject.java
示例11: createUser
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
public HomePageObject createUser(String userId, String password, String confirmPassword,
String firstName, String middleName, String lastName, String country){
setText("createUserForm:userName",userId);
setText("createUserForm:password",password);
setText("createUserForm:confirmPassword",confirmPassword);
setText("createUserForm:firstName",firstName);
setText("createUserForm:middleName",middleName);
setText("createUserForm:lastName",lastName);
try {
new Select(driver.findElement(By.id("createUserForm:country"))).selectByVisibleText(country);
} catch (Exception e){
return null;
}
driver.findElement(By.id("createUserForm:createButton")).click();
waitForPageToLoad();
if(isOnPage()){
return null;
} else {
return new HomePageObject(driver);
}
}
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:26,代码来源:CreateUserPageObject.java
示例12: doCreditCardPaymentOnPaymentPanel
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
private void doCreditCardPaymentOnPaymentPanel(Payment response) {
RemoteWebDriver driver = openFirefoxAtUrl(response.getRedirectLocation());
driver.findElement(By.name("selCC|VISA")).click();
WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.elementToBeClickable(By.id("cardnumber")));
driver.findElement(By.id("cardnumber")).sendKeys("4444333322221111");
driver.findElement(By.id("cvc")).sendKeys("123");
(new Select(driver.findElement(By.id("expiry-month")))).selectByValue("05");
(new Select(driver.findElement(By.id("expiry-year")))).selectByValue(getYear());
driver.findElement(By.name("profile_id")).sendKeys("x");
driver.findElement(By.id("right")).click();
wait.until(ExpectedConditions.elementToBeClickable(By.id("right")));
driver.findElement(By.id("right")).click();
}
示例13: selectOptionByText
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
/**
* Select option by option text.
*
* @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 optionText
* - dropdown option text
* @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 selectOptionByText(String locator, String replacement, String optionText)
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.selectByVisibleText(optionText);
LOGGER.info("Successfully selected option '" + optionText + "' from element '" + locator
+ "' with locator value '" + props.getProperty(locator) + "'");
}
示例14: 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) + "'");
}
示例15: createOidcBearerClient
import org.openqa.selenium.support.ui.Select; //导入依赖的package包/类
@Override
public String createOidcBearerClient(String clientName) {
try {
// .../auth/admin/master/console/#/create/client/foobar
driver.navigate().to(authUrl + "/admin/master/console/#/create/client/" + realm + "/");
DriverUtil.waitFor(driver, By.id("clientId"));
driver.findElement(By.id("clientId")).sendKeys(clientName);
driver.findElement(By.xpath("//button[contains(text(),'Save')]")).click();
DriverUtil.waitFor(driver, By.id("accessType"));
Select accessTypeSelect = new Select(driver.findElement(By.id("accessType")));
accessTypeSelect.selectByVisibleText(OpenIdAccessType.BEARER_ONLY.getLabel());
String clientId = driver.getCurrentUrl();
int lastSlash = clientId.lastIndexOf("/");
clientId = clientId.substring(lastSlash + 1);
driver.findElement(By.xpath("//button[contains(text(),'Save')]")).click();
return clientId;
} catch (InterruptedException | TimeoutException e) {
throw new IllegalStateException("Failed to ...", e);
}
}