当前位置: 首页>>代码示例>>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;未经允许,请勿转载。