Refine search
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); }
/** * Selects given options of select component. * * @param value String value of comma delimited field names which will be selected. */ @Override public void setValue(Object value) { selectField.click(); List<WebElement> options = selectField.findElements(By.cssSelector(SELECT_OPTIONS_CSS)); options.stream().filter(o -> value.toString().equals(o.getText())) .findFirst() .orElseThrow(() -> new NoSuchElementException( String.format("Option with text %s not found", value.toString()))).click(); }
private void typeNewFileName(String newFileName) { wait.forElementVisible(fileNameInput); if (Boolean.parseBoolean(fileNameInput.getAttribute("readonly"))) { throw new NoSuchElementException( "File name input is read only! This file already exist on this wiki"); } fileNameInput.clear(); fileNameInput.sendKeys(newFileName); waitForValueToBePresentInElementsAttributeByElement(fileNameInput, "value", newFileName); }
/** * Finds a pending method signature that includes the given text in the signature itself. */ public PendingSignature findSignature(String context) { for (WebElement e : all(by.xpath(".//div[starts-with(@id,'s-')]"))) { if (e.findElement(by.tagName("code")).getText().contains(context)) { return new PendingSignature(injector,e); } } throw new NoSuchElementException(context); }
public void adjustPosition(PositionsVideo position) { wait.forElementVisible(videoEmbedLayotRow); switch (position) { case LEFT: positionLayoutLeft.click(); break; case CENTER: positionLayoutCenter.click(); break; case RIGHT: positionLayoutRight.click(); break; default: throw new NoSuchElementException("Non-existing position selected"); } Log.log("adjustPosition", "position " + position.toString() + " selected", true); }
public String getImageUrl(String imageName) { for (WebElement elem : imagesNewFiles) { String href = elem.findElement(parentBy).getAttribute("href"); if (href.contains(imageName)) { return href; } } throw new NoSuchElementException("there is no " + imageName + " on Special:NewFiles page"); }
public <T extends View> T selectView(final Class<T> type, final String viewName) { final List<WebElement> viewTabs = this.getViewTabs(); int i = 0; for (final WebElement tab : viewTabs) { if (tab.getText().equals(viewName)) { tab.click(); if (i == 0) { // First tab redirects to Folder's home page return null; } else { return newInstance(type, injector, url("view/%s/", viewName)); } } i++; } throw new NoSuchElementException(String.format("There is no view with name [%s]", viewName)); }
/** * Get an option based on its visible text. * * @param optionText the text of the option we are trying to find * @return the option */ public WebElement getOption(final String optionText) { if (optionText == null) { throw new SystemException("option text must not be null"); } for (WebElement we : getOptions()) { if (optionText.equals(we.getText())) { return we; } } throw new NoSuchElementException("No option with text provided"); } }
public String getToolTipLine(int lineNo) throws NoSuchElementException { List<String> lines = new ArrayList<String>(); List<WebElement> toolTipLines = toolTip.findElements(By.cssSelector("text tspan")); for (WebElement toolTipLine : toolTipLines) { lines.add(toolTipLine.getText()); } if (lineNo > lines.size()) { throw new NoSuchElementException("There is no line " + lineNo + "! There are only " + lines.size() + " lines in the tool tip"); } //We return line - 1 because the lines Array starts a 0 not 1 return lines.get(lineNo - 1); }
/** * Selects first radio button that has a value matching the specified argument. * * @param value The value to match against. */ public void selectByValue(String value) { WebElement matchingButton = getButtons().stream() .filter(b -> value.equals(b.getAttribute("value"))) .findFirst() .orElseThrow(() -> new NoSuchElementException( String.format("Cannot locate radio button with value: %s", value))); selectButton(matchingButton); }
break; case "id": WebElement option = select.findElement(By.id(oLoc.arg)); if (option.isSelected() ^ selectOrDeselect) option.click(); break; case "index": String msg = e.getMessage(); int nlIndex = msg.indexOf('\n'); if (nlIndex > 0) {
private boolean isDependencyPathsExists(WebElement traitsElement, String key, final List<String> foundPaths, String dependencyName) { String id = dependencyName + "-"+key; try { List<WebElement> pathElements = traitsElement.findElements(By.xpath("//ul[@id='" + id +"']/li")); if ( pathElements.size() != foundPaths.size()) { return false; } List<String> pathsOnPage = new ArrayList<>(); for (WebElement webElement : pathElements) { pathsOnPage.add(webElement.getText()); } pathsOnPage.removeAll(foundPaths); if (pathsOnPage.isEmpty()) { return true; } } catch (org.openqa.selenium.NoSuchElementException e) { System.err.println("Element not found " + e.getLocalizedMessage()); } return false; }
private boolean isDependencyPropertyExists(WebElement traitsElement, String key, String value, String dependencyName) { String id = dependencyName +"-"+key; try { WebElement header = traitsElement.findElement(By.id(id)); if (header != null && header.getText().endsWith(value)) { return true; } } catch (org.openqa.selenium.NoSuchElementException e) { System.err.println("Element not found " + e.getLocalizedMessage()); } return false; }
public void typeInParam(String paramName, String text) { waitForDialogVisible(); if (isElementOnPage(TEMPLATE_PARAMS_BY)) { WebElement targetParam = Elements.getElementByChildText(templateParams, PARAM_LABEL_BY, paramName ); WebElement targetParamInput = targetParam.findElement(PARAM_INPUT_BY); targetParamInput.sendKeys(text); waitForValueToBePresentInElementsAttributeByElement(targetParamInput, "value", text); } else { throw new NoSuchElementException("This template has no param."); } Log.log("typeInParam", "Type " + text + " in the " + paramName + " field.", true, driver); }
@Override public void checkIfPresent(WebElement element) throws NoSuchElementException { if (element == null) throw new NoSuchElementException("Element is null"); element.isDisplayed(); }
private WebElement findElement(WebElement context, By selector) { try { return context.findElement(selector); } catch (NoSuchElementException x) { // this is often the best place to set a breakpoint String msg = String.format("Unable to locate %s in %s", selector, driver.getCurrentUrl()); throw new NoSuchElementException(msg, x); } }
/** * @return The first selected option in this select tag (or the currently selected option in a * normal select) */ public WebElement getFirstSelectedOption() { for (WebElement option : getOptions()) { if (option.isSelected()) { return option; } } throw new NoSuchElementException("No options are selected"); }
@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; }
@Override public Object getTarget() { try { return dropProxyAndFindElement(by, searchContext); } catch (NoSuchElementException ex) { throw new NoSuchElementException((by instanceof ByIdOrName ? EMPTY_FIND_BY_WARNING : "") + ex.getMessage(), ex); } } });
private boolean isElementVisible(WebElement element) { try { return element.isDisplayed(); } catch (NoSuchElementException e) { Log.info(e.getMessage()); return false; } }