本文整理匯總了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);
}
}