本文整理了Java中org.openqa.selenium.NoSuchElementException.<init>()
方法的一些代码示例,展示了NoSuchElementException.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NoSuchElementException.<init>()
方法的具体详情如下:
包路径:org.openqa.selenium.NoSuchElementException
类名称:NoSuchElementException
方法名:<init>
暂无
代码示例来源:origin: galenframework/galen
public WebElement findElement(SearchContext searchContext) {
List<WebElement> elements = searchContext.findElements(by);
if (next != null) {
if (index > 0 ) {
if (index <= elements.size()) {
return next.findElement(elements.get(index - 1));
}
} else {
if (elements.size() > 0) {
return next.findElement(elements.get(0));
}
}
} else {
if (index > 0) {
if (index <= elements.size()) {
return elements.get(index - 1);
}
} else {
if (elements.size() > 0) {
return elements.get(0);
}
}
}
throw new NoSuchElementException(by.toString() + " | index " + index);
}
代码示例来源: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: appium/java-client
@Override
public WebElement findElement(SearchContext context) {
return bys.stream()
.map(by -> getSearchingFunction(by).apply(context))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Cannot locate an element using " + toString()));
}
}
代码示例来源:origin: appium/java-client
private AndroidElement findElementByText(String text) {
return driver.findElements(id("android:id/title")).stream().filter(androidElement ->
text.equals(androidElement.getText())).findFirst()
.orElseThrow(() ->
new NoSuchElementException(String.format("There is no element with the text '%s'", text)));
}
代码示例来源:origin: appium/java-client
@Override
public WebElement findElement(SearchContext context) {
AppiumFunction<SearchContext, WebElement> searchingFunction = null;
for (By by: bys) {
searchingFunction = Optional.ofNullable(searchingFunction != null
? searchingFunction.andThen(getSearchingFunction(by)) : null).orElse(getSearchingFunction(by));
}
FluentWait<SearchContext> waiting = new FluentWait<>(context);
try {
checkNotNull(searchingFunction);
return waiting.until(searchingFunction);
} catch (TimeoutException e) {
throw new NoSuchElementException("Cannot locate an element using " + toString());
}
}
}
代码示例来源:origin: appium/java-client
/**
* Find the element.
*/
public WebElement findElement() {
if (cachedElement != null && shouldCache) {
return cachedElement;
}
By bySearching = getBy(this.by, searchContext);
try {
WebElement result = waitFor(() ->
searchContext.findElement(bySearching));
if (shouldCache) {
cachedElement = result;
}
return result;
} catch (TimeoutException | StaleElementReferenceException e) {
throw new NoSuchElementException(format(exceptionMessageIfElementNotFound, bySearching.toString()), e);
}
}
代码示例来源:origin: qaprosoft/carina
/** Scroll Timeout check
* @param startTime - Long initial time for timeout count down
**/
public static void checkTimeout(long startTime){
long elapsed = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())-startTime;
if (elapsed > SCROLL_TIMEOUT) {
throw new NoSuchElementException("Scroll timeout has been reached..");
}
}
代码示例来源:origin: net.serenity-bdd/serenity-core
private void throwNoSuchElementExceptionWithCauseIfPresent(final Throwable timeout, final String defaultMessage) {
String timeoutMessage = (timeout.getCause() != null) ? timeout.getCause().getMessage() : timeout.getMessage();
String finalMessage = (StringUtils.isNotEmpty(timeoutMessage)) ? timeoutMessage : defaultMessage;
throw new NoSuchElementException(finalMessage, timeout);
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
@Override
public List<WebElement> findElementsByClassName(String className) {
if (className.indexOf(' ') != -1) {
throw new NoSuchElementException("Compound class names not permitted");
}
return findElementsByCssSelector("." + className);
}
代码示例来源:origin: net.thucydides/thucydides-core
/**
* Check that all of the specified texts appears somewhere in the page.
*/
public void shouldContainAllText(final String... textValues) {
if (!containsAllText(textValues)) {
String errorMessage = String.format(
"One of the text elements in '%s' was not found in the page", (Object[]) textValues);
throw new NoSuchElementException(errorMessage);
}
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
@Override
public WebElement findElementByClassName(String className) {
if (className.indexOf(' ') != -1) {
throw new NoSuchElementException("Compound class names not permitted");
}
return findElementByCssSelector("." + className);
}
代码示例来源:origin: io.appium/java-client
@Override
public WebElement findElement(SearchContext context) {
return bys.stream()
.map(by -> getSearchingFunction(by).apply(context))
.filter(Optional::isPresent)
.map(Optional::get)
.findFirst()
.orElseThrow(() -> new NoSuchElementException("Cannot locate an element using " + toString()));
}
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
@Override
public WebElement findElementByCssSelector(String using) {
List<WebElement> allElements = parent.findElementsByCssSelector(using);
allElements = findChildNodes(allElements);
if (allElements.isEmpty()) {
throw new NoSuchElementException("Cannot find child element using css: " + using);
}
return allElements.get(0);
}
代码示例来源:origin: com.opera/operadriver
private List<WebElement> findMultipleElements(String using, String type) {
Integer id = debugger.executeScriptOnObject(using, objectId);
if (id == null) {
throw new NoSuchElementException("Cannot find element(s) with " + type);
}
return parent.processElements(id);
}
代码示例来源:origin: net.serenity-bdd/serenity-core
@SuppressWarnings("unchecked")
@Override
public List<WebElement> findElements(SearchContext context) {
List<WebElement> elements = (List<WebElement>) ((JavascriptExecutor) context)
.executeScript("var elements = $(arguments[0]).get(); return ((elements.length) ? elements : null)",
jQuerySelector);
if (elements != null){
return elements;
}
throw new NoSuchElementException("Cannot locate elements using " + toString());
}
代码示例来源:origin: net.serenity-bdd/core
@Override
public WebElement findElement(SearchContext context) {
WebElement element = (WebElement) ((JavascriptExecutor) context)
.executeScript("return $(arguments[0]).get(0)", jQuerySelector);
if (element != null){
return element;
}
throw new NoSuchElementException("Cannot locate element using " + toString());
}
代码示例来源:origin: qaprosoft/carina
private WebElement findElement(long timeout) {
if (element != null) {
return element;
}
if (isPresent(timeout)) {
//TODO: investigate maybe searchContext better to use here!
element = getDriver().findElement(by);
} else {
throw new NoSuchElementException("Unable to detect element using By: " + by.toString());
}
return element;
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
@Override
public WebElement findElementById(String id) {
if (!(lastPage() instanceof HtmlPage)) {
throw new NoSuchElementException("Unable to locate element by id for " + lastPage());
}
try {
HtmlElement element = ((HtmlPage) lastPage()).getHtmlElementById(id);
return newHtmlUnitWebElement(element);
} catch (ElementNotFoundException e) {
throw new NoSuchElementException("Unable to locate element with ID: " + id);
}
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
@Override
public WebElement findElementByTagName(String name) {
if (!(lastPage() instanceof HtmlPage)) {
throw new IllegalStateException("Unable to locate element by name for " + lastPage());
}
NodeList allElements = ((HtmlPage) lastPage()).getElementsByTagName(name);
if (allElements.getLength() > 0) {
return newHtmlUnitWebElement((HtmlElement) allElements.item(0));
}
throw new NoSuchElementException("Unable to locate element with name: " + name);
}
代码示例来源:origin: org.seleniumhq.selenium/selenium-htmlunit-driver
@Override
public WebElement findElementByName(String name) {
if (!(lastPage() instanceof HtmlPage)) {
throw new IllegalStateException("Unable to locate element by name for " + lastPage());
}
List<DomElement> allElements = ((HtmlPage) lastPage()).getElementsByName(name);
if (!allElements.isEmpty()) {
return newHtmlUnitWebElement(allElements.get(0));
}
throw new NoSuchElementException("Unable to locate element with name: " + name);
}
内容来源于网络,如有侵权,请联系作者删除!