本文整理匯總了Java中org.openqa.selenium.WebElement.isSelected方法的典型用法代碼示例。如果您正苦於以下問題:Java WebElement.isSelected方法的具體用法?Java WebElement.isSelected怎麽用?Java WebElement.isSelected使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.openqa.selenium.WebElement
的用法示例。
在下文中一共展示了WebElement.isSelected方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateValue
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* Update the specified element with the indicated value
*
* @param element target element (checkbox)
* @param value desired value
* @return 'true' if element value changed; otherwise 'false'
*/
public static boolean updateValue(WebElement element, boolean value) {
Objects.requireNonNull(element, "[element] must be non-null");
String tagName = element.getTagName().toLowerCase();
if ("input".equals(tagName) && "checkbox".equals(element.getAttribute("type"))) {
if (element.isSelected() != value) {
element.click();
return true;
} else {
return false;
}
}
return updateValue(element, Boolean.toString(value));
}
示例2: isSelectedOnNonSelectableComponents
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
public void isSelectedOnNonSelectableComponents() throws Throwable {
driver = new JavaDriver();
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
WebElement element1 = driver.findElement(By.name("text-field"));
try {
element1.isSelected();
throw new MissingException(UnsupportedCommandException.class);
} catch (UnsupportedCommandException e) {
}
}
示例3: checkAllCheckBoxes
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
@Action(object = ObjectType.BROWSER, desc = "Check all the check boxes in the context")
public void checkAllCheckBoxes() {
try {
List<WebElement> checkboxes = Driver.findElements(By.cssSelector("input[type=checkbox]"));
if (checkboxes.isEmpty()) {
Report.updateTestLog(Action, "No Checkbox present in the page", Status.WARNING);
} else {
for (WebElement checkbox : checkboxes) {
if (checkbox.isDisplayed() && !checkbox.isSelected()) {
checkbox.click();
}
}
Report.updateTestLog(Action, "All checkboxes are checked", Status.PASS);
}
} catch (Exception ex) {
Report.updateTestLog(Action, "Error while checking checkboxes - " + ex, Status.FAIL);
Logger.getLogger(CheckBox.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例4: check
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* Check the check box
*/
@Override
@PublicAtsApi
public void check() {
new MobileElementState(this).waitToBecomeExisting();
try {
WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
if (!checkboxElement.isSelected()) {
if (appiumDriver instanceof AndroidDriver) {
// checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
} else {
checkboxElement.click();
}
}
} catch (Exception se) {
throw new MobileOperationException(this, "check", se);
}
UiEngineUtilities.sleep();
}
示例5: unsetValue
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* unselect a value
*
* @param value the value to unselect
*/
@Override
@PublicAtsApi
public void unsetValue(
String value ) {
new HiddenHtmlElementState(this).waitToBecomeExisting();
HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this);
List<WebElement> optionElements = selectElement.findElements(By.tagName("option"));
for (WebElement el : optionElements) {
if (el.getText().equals(value)) {
if (el.isSelected()) {
((HtmlUnitWebElement) el).click();
UiEngineUtilities.sleep();
}
return;
}
}
throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
+ this.toString() + ")");
}
示例6: getValues
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* @return the selected value
*/
@Override
@PublicAtsApi
public String[] getValues() {
new HiddenHtmlElementState(this).waitToBecomeExisting();
HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this);
List<String> values = new ArrayList<String>();
List<WebElement> optionElements = selectElement.findElements(By.tagName("option"));
for (WebElement element : optionElements) {
if (element.isSelected()) {
values.add(element.getText());
}
}
if (values.isEmpty()) {
throw new SeleniumOperationException("There is no selected 'option' in " + this.toString());
}
return values.toArray(new String[0]);
}
示例7: getValue
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* @return the single selection value
*/
@Override
@PublicAtsApi
public String getValue() {
new HiddenHtmlElementState(this).waitToBecomeExisting();
HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this);
List<WebElement> optionElements = selectElement.findElements(By.tagName("option"));
for (WebElement element : optionElements) {
if (element.isSelected()) {
return element.getText();
}
}
throw new SeleniumOperationException("There is no selected 'option' in " + this.toString());
}
示例8: check
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* Check the check box
*/
@Override
@PublicAtsApi
public void check() {
new RealHtmlElementState(this).waitToBecomeExisting();
WebElement checkBoxElement = RealHtmlElementLocator.findElement(this);
if (!checkBoxElement.isEnabled()) {
throw new UnsupportedOperationException("You may not check a disabled element."
+ toString());
}
if (!checkBoxElement.isSelected()) {
checkBoxElement.click();
}
UiEngineUtilities.sleep();
}
示例9: unCheck
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* Uncheck the check box
*/
@Override
@PublicAtsApi
public void unCheck() {
new RealHtmlElementState(this).waitToBecomeExisting();
WebElement checkBoxElement = RealHtmlElementLocator.findElement(this);
if (!checkBoxElement.isEnabled()) {
throw new UnsupportedOperationException("You may not uncheck a disabled element."
+ toString());
}
if (checkBoxElement.isSelected()) {
checkBoxElement.click();
}
UiEngineUtilities.sleep();
}
示例10: unsetValue
import org.openqa.selenium.WebElement; //導入方法依賴的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() + ")");
}
示例11: isSelected
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
public void isSelected() throws Throwable {
driver = new JavaDriver();
SwingUtilities.invokeAndWait(new Runnable() {
@Override public void run() {
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
WebElement element1 = driver.findElement(By.name("click-me"));
element1.isSelected();
}
示例12: checkRadioList
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* Checks that given value is matching the selected radio list button.
*
* @param pageElement
* The page element
* @param value
* The value to check the selection from
* @return true if the given value is selected, false otherwise.
* @throws FailureException
* if the scenario encounters a functional error
*/
protected boolean checkRadioList(PageElement pageElement, String value) throws FailureException {
try {
List<WebElement> radioButtons = Context.waitUntil(ExpectedConditions.presenceOfAllElementsLocatedBy(Utilities.getLocator(pageElement)));
for (WebElement button : radioButtons) {
if (button.getAttribute(VALUE).equalsIgnoreCase(value) && button.isSelected()) {
return true;
}
}
} catch (Exception e) {
new Result.Failure<>(e.getMessage(), Messages.getMessage(Messages.FAIL_MESSAGE_UNABLE_TO_FIND_ELEMENT), true, pageElement.getPage().getCallBack());
}
return false;
}
示例13: clearCheckbox
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* Clears the specified checkbox button. Supports well-formed labels and inputs nested inside the label.
* @param labelText The checkbox button label
*/
public void clearCheckbox(String labelText) {
WebElement checkboxElement = findCheckbox(labelText);
// click checkbox if already selected, otherwise leave as not selected
if (checkboxElement.isSelected()) {
checkboxElement.click();
}
}
示例14: setValue
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* select a value
*
* @param value the value to select
*/
@Override
@PublicAtsApi
public void setValue(
String value ) {
new HiddenHtmlElementState(this).waitToBecomeExisting();
HtmlUnitWebElement selectElement = HiddenHtmlElementLocator.findElement(this);
if (selectElement.getAttribute("multiple") == null) {
throw new SeleniumOperationException("Not a multi-select. You may only add a selection to a select that supports multiple selections. ("
+ this.toString() + ")");
}
List<WebElement> optionElements = selectElement.findElements(By.tagName("option"));
for (WebElement el : optionElements) {
if (el.getText().equals(value)) {
if (!el.isSelected()) {
((HtmlUnitWebElement) el).click();
UiEngineUtilities.sleep();
}
return;
}
}
throw new SeleniumOperationException("Option with label '" + value + "' not found. ("
+ this.toString() + ")");
}
示例15: isChecked
import org.openqa.selenium.WebElement; //導入方法依賴的package包/類
/**
* Tells whether the check box is checked
*/
@Override
@PublicAtsApi
public boolean isChecked() {
new RealHtmlElementState(this).waitToBecomeExisting();
WebElement checkBoxElement = RealHtmlElementLocator.findElement(this);
return checkBoxElement.isSelected();
}