當前位置: 首頁>>代碼示例>>Java>>正文


Java NoSuchElementException類代碼示例

本文整理匯總了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;
}
 
開發者ID:anilpandeykiet,項目名稱:POM_HYBRID_FRAMEOWRK,代碼行數:24,代碼來源:WebUtilities.java

示例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;
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:23,代碼來源:CyleSearchStrategy.java

示例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;
        }
    };
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:27,代碼來源:Coordinators.java

示例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();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:RealHtmlMultiSelectList.java

示例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();
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:23,代碼來源:RealHtmlSingleSelectList.java

示例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;
        }

    });
}
 
開發者ID:porscheinformatik,項目名稱:selenium-components,代碼行數:23,代碼來源:SeleniumConditions.java

示例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;
    }
}
 
開發者ID:porscheinformatik,項目名稱:selenium-components,代碼行數:22,代碼來源:SelectableSeleniumComponent.java

示例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;
    }
}
 
開發者ID:porscheinformatik,項目名稱:selenium-components,代碼行數:22,代碼來源:EditableSeleniumComponent.java

示例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;
    }
}
 
開發者ID:porscheinformatik,項目名稱:selenium-components,代碼行數:22,代碼來源:EditableSeleniumComponent.java

示例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;
    }
}
 
開發者ID:porscheinformatik,項目名稱:selenium-components,代碼行數:22,代碼來源:VisibleSeleniumComponent.java

示例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
    }
}
 
開發者ID:porscheinformatik,項目名稱:selenium-components,代碼行數:17,代碼來源:TagsInputComponent.java

示例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();
  }
}
 
開發者ID:google,項目名稱:devtools-driver,代碼行數:20,代碼來源:RemoteWebElement.java

示例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);
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:29,代碼來源:WebDriverWrapper.java

示例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();
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:22,代碼來源:WebDriverWrapper.java

示例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);
                });
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:22,代碼來源:WebDriverWrapper.java


注:本文中的org.openqa.selenium.NoSuchElementException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。