本文整理汇总了Java中org.openqa.selenium.NoSuchElementException类的典型用法代码示例。如果您正苦于以下问题:Java NoSuchElementException类的具体用法?Java NoSuchElementException怎么用?Java NoSuchElementException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NoSuchElementException类属于org.openqa.selenium包,在下文中一共展示了NoSuchElementException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: waitForElementToAppear
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Wait for element to appear.
*
* @param driver the driver
* @param element the element
* @param logger the logger
*/
public static boolean waitForElementToAppear(WebDriver driver, WebElement element, ExtentTest logger) {
boolean webElementPresence = false;
try {
Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(2, TimeUnit.SECONDS)
.withTimeout(60, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
fluentWait.until(ExpectedConditions.visibilityOf(element));
if (element.isDisplayed()) {
webElementPresence= true;
}
} catch (TimeoutException toe) {
logger.log(LogStatus.ERROR, "Timeout waiting for webelement to be present<br></br>" + toe.getStackTrace());
} catch (Exception e) {
logger.log(LogStatus.ERROR, "Exception occured<br></br>" + e.getStackTrace());
}
return webElementPresence;
}
示例2: cyleFindElement
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
private WebElement cyleFindElement(List<By> byList)
{
WebElement webEle = null;
for (By by : byList)
{
try
{
webEle = findElement(by);
}
catch (NoSuchElementException e)
{
}
if (webEle != null)
{
return webEle;
}
}
return null;
}
示例3: invisibilityOfElementLocated
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Returns a 'wait' proxy that determines if an element is either hidden or non-existent.
*
* @param locator web element locator
* @return 'true' if the element is hidden or non-existent; otherwise 'false'
*/
public static Coordinator<Boolean> invisibilityOfElementLocated(final By locator) {
return new Coordinator<Boolean>() {
@Override
public Boolean apply(SearchContext context) {
try {
return !(context.findElement(locator).isDisplayed());
} catch (NoSuchElementException | StaleElementReferenceException e) {
// NoSuchElementException: The element is not present in DOM.
// StaleElementReferenceException: Implies that element no longer exists in the DOM.
return true;
}
}
@Override
public String toString() {
return "element to no longer be visible: " + locator;
}
};
}
示例4: setValue
import org.openqa.selenium.NoSuchElementException; //导入依赖的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();
}
示例5: setValue
import org.openqa.selenium.NoSuchElementException; //导入依赖的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();
}
示例6: get
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
@Override
public Boolean get()
{
return SeleniumUtils.retryOnStale(() -> {
try
{
WebElement element = component.element();
if (shouldBeVisible)
{
return element != null && element.isDisplayed();
}
return element == null || !element.isDisplayed();
}
catch (NoSuchElementException e)
{
return shouldBeVisible ? false : true;
}
});
}
示例7: isSelected
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Returns true if the component is selected. Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for
* the component to become available.
*
* @return true if selected
*/
default boolean isSelected()
{
try
{
return SeleniumUtils.retryOnStale(() -> {
WebElement element = element();
return element.isSelected();
});
}
catch (NoSuchElementException e)
{
return false;
}
}
示例8: isEditable
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Returns true if the component is editable. Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for
* the component to become available.
*
* @return true if editable
*/
default boolean isEditable()
{
try
{
return SeleniumUtils.retryOnStale(() -> {
WebElement element = element();
return element.isDisplayed() && element.isEnabled();
});
}
catch (NoSuchElementException e)
{
return false;
}
}
示例9: isEnabled
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Returns true if the component is enabled. Waits {@link SeleniumGlobals#getShortTimeoutInSeconds()} seconds for
* the component to become available.
*
* @return true if enabled
*/
default boolean isEnabled()
{
try
{
return SeleniumUtils.retryOnStale(() -> {
WebElement element = element();
return element.isEnabled();
});
}
catch (NoSuchElementException e)
{
return false;
}
}
示例10: isVisible
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Returns true if a {@link WebElement} described by this component is visible. By default it checks, if the element
* is visible. This method has no timeout, it does not wait for the component to become existent.
*
* @return true if the component is visible
*/
default boolean isVisible()
{
try
{
return SeleniumUtils.retryOnStale(() -> {
WebElement element = element();
return element.isDisplayed();
});
}
catch (NoSuchElementException e)
{
return false;
}
}
示例11: clear
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
public void clear()
{
try
{
List<WebElement> removeButtons = searchContext().findElements(By.className("remove-button"));
for (WebElement removeButton : removeButtons)
{
removeButton.click();
}
}
catch (NoSuchElementException e)
{
//Nothing to do. May be empty
}
}
示例12: findElementByXpath
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
public RemoteWebElement findElementByXpath(String xpath) throws Exception {
String f =
"(function(xpath, element) { var result = "
+ JsAtoms.xpath("xpath", "element")
+ ";"
+ "return result;})";
JsonObject response =
getInspectorResponse(
f,
false,
callArgument().withValue(xpath),
callArgument().withObjectId(getRemoteObject().getId()));
RemoteObject ro = inspector.cast(response);
if (ro == null) {
throw new NoSuchElementException("cannot find element by Xpath " + xpath);
} else {
return ro.getWebElement();
}
}
示例13: enterIntoFieldInFieldset
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Enters the specified text into the field, within the specified fieldset.
* @param text The text to enter
* @param fieldLabel The field label
* @param fieldsetLabel The fieldset label
*/
public void enterIntoFieldInFieldset(String text, String fieldLabel, String fieldsetLabel) {
WebElement fieldsetElement;
try {
// find the fieldset with the fieldset label
fieldsetElement = webDriver.findElement(
By.xpath("//label[contains(text(),'" + fieldsetLabel + "')]/ancestor::fieldset[1]"));
} catch (NoSuchElementException noSuchElement) {
fieldsetElement = findFieldsetByLegend(fieldsetLabel);
}
// find the specified label (with the for="id" attribute)...
WebElement labelElement = fieldsetElement.findElement(
By.xpath(".//label[contains(text(),'" + fieldLabel + "')]"));
// find the text element with id matching the for attribute
// (search in the fieldset rather than the whole page, to get around faulty HTML where id's aren't unique!)
WebElement textElement = fieldsetElement.findElement(By.id(labelElement.getAttribute("for")));
textElement.clear();
textElement.sendKeys(text);
}
示例14: selectRadio
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Selects the specified radio button. Supports well-formed labels and radio buttons nested inside the label.
* @param labelText The radio button label
*/
public void selectRadio(String labelText) {
try {
// find the input associated with the specified (well-formed) label...
WebElement labelElement = webDriver.findElement(By.xpath("//label[contains(text(),'" + labelText + "')]"));
webDriver.findElement(By.id(labelElement.getAttribute("for"))).click();
} catch (NoSuchElementException | IllegalArgumentException ex) {
webDriver.findElements(By.tagName("label")).stream()
.filter((l) -> l.getText().contains(labelText)) // label with text
.map((l) -> l.findElement(By.xpath("./input[@type = 'radio']"))) // nested radio
.findFirst().orElseThrow(() -> {
String message = "No radio button found with label (well-formed or nested): " + labelText;
logger.error(message);
return new IllegalArgumentException(message);
}).click();
}
}
示例15: findCheckbox
import org.openqa.selenium.NoSuchElementException; //导入依赖的package包/类
/**
* Finds the specified checkbox button. Supports well-formed labels and inputs nested inside the label.
* @param labelText The checkbox button label
*/
private WebElement findCheckbox(String labelText) {
try {
// find the input associated with the specified (well-formed) label...
WebElement labelElement = webDriver.findElement(By.xpath("//label[contains(text(),'" + labelText + "')]"));
return webDriver.findElement(By.id(labelElement.getAttribute("for")));
} catch (NoSuchElementException | IllegalArgumentException ex) {
return webDriver.findElements(By.tagName("label")).stream()
.filter((label) -> label.getText().contains(labelText)) // label with text
.map((label) -> label.findElement(By.xpath("./input[@type = 'checkbox']"))) // nested checkbox
.findFirst().orElseThrow(() -> {
String message = "No checkbox button found with label (well-formed or nested): " + labelText;
logger.error(message);
return new IllegalArgumentException(message);
});
}
}