本文整理了Java中org.openqa.selenium.support.ui.Select.<init>()
方法的一些代码示例,展示了Select.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Select.<init>()
方法的具体详情如下:
包路径:org.openqa.selenium.support.ui.Select
类名称:Select
方法名:<init>
[英]Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not, then an UnexpectedTagNameException is thrown.
[中]建造师。检查给定元素是否确实是SELECT标记。如果不是,则会抛出一个意外的TagNameException。
代码示例来源:origin: selenide/selenide
private String getSelectedOptionsTexts(WebElement element) {
List<WebElement> selectedOptions = new Select(element).getAllSelectedOptions();
StringBuilder sb = new StringBuilder();
for (WebElement selectedOption : selectedOptions) {
sb.append(selectedOption.getText());
}
return sb.toString();
}
代码示例来源:origin: selenide/selenide
@Override
public List<WebElement> getElements() {
return new Select(selectElement.getWebElement()).getAllSelectedOptions();
}
代码示例来源:origin: selenide/selenide
@Override
public Object execute(SelenideElement proxy, WebElementSource selectField, Object[] args) {
Select select = new Select(selectField.getWebElement());
if (args[0] instanceof String) {
selectOptionByValue(selectField, select, (String) args[0]);
}
else if (args[0] instanceof String[]) {
String[] values = (String[]) args[0];
for (String value : values) {
selectOptionByValue(selectField, select, value);
}
}
return null;
}
代码示例来源:origin: selenide/selenide
@Override
public SelenideElement execute(SelenideElement proxy, WebElementSource selectElement, Object[] args) {
return wrap(selectElement.driver(), new Select(selectElement.getWebElement()).getFirstSelectedOption());
}
}
代码示例来源:origin: selenide/selenide
private void selectOptionsByTexts(WebElementSource selectField, String[] texts) {
Select select = new Select(selectField.getWebElement());
for (String text : texts) {
try {
select.selectByVisibleText(text);
}
catch (NoSuchElementException e) {
throw new ElementNotFound(selectField.driver(), selectField.getSearchCriteria() + "/option[text:" + text + ']', exist, e);
}
}
}
代码示例来源:origin: selenide/selenide
private void selectOptionsByIndexes(WebElementSource selectField, int[] indexes) {
Select select = new Select(selectField.getWebElement());
for (int index : indexes) {
try {
select.selectByIndex(index);
}
catch (NoSuchElementException e) {
throw new ElementNotFound(selectField.driver(), selectField.getSearchCriteria() + "/option[index:" + index + ']', exist, e);
}
}
}
}
代码示例来源:origin: selenide/selenide
@Override
public Void execute(SelenideElement proxy, WebElementSource selectField, Object[] args) {
String text = (String) args[0];
WebElement element = selectField.getWebElement();
Select select = new Select(element);
List<WebElement> options = element.findElements(By.xpath(
".//option[contains(normalize-space(.), " + Quotes.escape(text) + ")]"));
if (options.isEmpty()) {
throw new NoSuchElementException("Cannot locate option containing text: " + text);
}
for (WebElement option : options) {
setSelected(option);
if (!select.isMultiple()) {
break;
}
}
return null;
}
代码示例来源:origin: spring-io/initializr
private Object getInputValue(WebElement input) {
Object value = null;
String type = input.getAttribute("type");
if ("select".equals(input.getTagName())) {
Select select = new Select(input);
if (select.isMultiple()) {
value = select.getAllSelectedOptions().stream().map(this::getValue)
.collect(Collectors.toList());
}
else {
value = getValue(select.getFirstSelectedOption());
}
}
else if (Arrays.asList("checkbox", "radio").contains(type)) {
if (input.isSelected()) {
value = getValue(input);
}
else {
if (Objects.equals(type, "checkbox")) {
value = false;
}
}
}
else {
value = getValue(input);
}
return value;
}
代码示例来源:origin: TEAMMATES/teammates
public void selectResponseTextDropdown(int qnNumber, int responseNumber, int responseSubNumber, String text) {
WebElement element = browser.driver.findElement(
By.id(Const.ParamsNames.FEEDBACK_RESPONSE_TEXT + "-"
+ qnNumber + "-" + responseNumber
+ "-" + responseSubNumber));
Select dropdown = new Select(element);
dropdown.selectByVisibleText(text);
}
代码示例来源:origin: TEAMMATES/teammates
public String getDropdownSelectedValue(WebElement element) {
Select select = new Select(element);
return select.getFirstSelectedOption().getAttribute("value");
}
代码示例来源:origin: TEAMMATES/teammates
public int getSelectedQuestionNumber(int qnNumber) {
if (isQuestionEnabled(qnNumber)) {
Select qnNumSelect = new Select(getSelectQuestionNumberDropdown(qnNumber));
return Integer.parseInt(qnNumSelect.getFirstSelectedOption().getText().trim());
}
//substring trims colon from the retrieved question number text
String questionNumber = getSelectQuestionNumberStatic(qnNumber).getText();
return Integer.parseInt(questionNumber.substring(0, questionNumber.length() - 1));
}
代码示例来源:origin: TEAMMATES/teammates
public void selectRecipient(int qnNumber, int responseNumber, String recipientName) {
Select selectElement = new Select(browser.driver.findElement(
By.name(Const.ParamsNames.FEEDBACK_RESPONSE_RECIPIENT + "-" + qnNumber + "-" + responseNumber)));
selectElement.selectByVisibleText(recipientName);
}
代码示例来源:origin: TEAMMATES/teammates
/**
* Selects student nationality from the dropdown list if the nationality is
* valid, otherwise it fails with a message.
*/
public void selectNationality(String studentNationality) {
if (NationalityHelper.getNationalities().contains(studentNationality) || "".equals(studentNationality)) {
Select dropdown = new Select(studentNationalityDropdown);
dropdown.selectByValue(studentNationality);
} else {
fail("Given nationality " + studentNationality + " is not valid!");
}
}
代码示例来源:origin: TEAMMATES/teammates
public void displayByRecipientQuestionGiver() {
displayEditSettingsWindow();
Select select = new Select(browser.driver.findElement(By.name(Const.ParamsNames.FEEDBACK_RESULTS_SORTTYPE)));
select.selectByVisibleText("Group by - Recipient > Question > Giver");
submitEditForm();
}
代码示例来源:origin: TEAMMATES/teammates
public void displayByGiverRecipientQuestion() {
displayEditSettingsWindow();
Select select = new Select(browser.driver.findElement(By.name(Const.ParamsNames.FEEDBACK_RESULTS_SORTTYPE)));
select.selectByVisibleText("Group by - Giver > Recipient > Question");
submitEditForm();
}
代码示例来源:origin: TEAMMATES/teammates
public void displayByGiverQuestionRecipient() {
displayEditSettingsWindow();
Select select = new Select(browser.driver.findElement(By.name(Const.ParamsNames.FEEDBACK_RESULTS_SORTTYPE)));
select.selectByVisibleText("Group by - Giver > Question > Recipient");
submitEditForm();
}
代码示例来源:origin: TEAMMATES/teammates
public void displayByRecipientGiverQuestion() {
displayEditSettingsWindow();
Select select = new Select(browser.driver.findElement(By.name(Const.ParamsNames.FEEDBACK_RESULTS_SORTTYPE)));
select.selectByVisibleText("Group by - Recipient > Giver > Question");
submitEditForm();
}
代码示例来源:origin: TEAMMATES/teammates
public void displayByQuestion() {
displayEditSettingsWindow();
Select select = new Select(browser.driver.findElement(By.name(Const.ParamsNames.FEEDBACK_RESULTS_SORTTYPE)));
select.selectByVisibleText("Group by - Question");
submitEditForm();
}
代码示例来源:origin: TEAMMATES/teammates
public void filterResponsesForSection(String section) {
displayEditSettingsWindow();
Select select = new Select(browser.driver.findElements(By.name(Const.ParamsNames.FEEDBACK_RESULTS_GROUPBYSECTION))
.get(1));
select.selectByVisibleText(section);
submitEditForm();
}
代码示例来源:origin: TEAMMATES/teammates
public void filterResponsesForAllSections() {
displayEditSettingsWindow();
Select select = new Select(browser.driver.findElements(By.name(Const.ParamsNames.FEEDBACK_RESULTS_GROUPBYSECTION))
.get(1));
select.selectByVisibleText("All");
submitEditForm();
}
内容来源于网络,如有侵权,请联系作者删除!