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


Java SearchContext.findElements方法代碼示例

本文整理匯總了Java中org.openqa.selenium.SearchContext.findElements方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchContext.findElements方法的具體用法?Java SearchContext.findElements怎麽用?Java SearchContext.findElements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.openqa.selenium.SearchContext的用法示例。


在下文中一共展示了SearchContext.findElements方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visibilityOfAnyElementLocated

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Returns a 'wait' proxy that determines if any element matched by the specified locator is visible
 * 
 * @param locator web element locator
 * @return web element reference; 'null' if no matching elements are visible
 */
public static Coordinator<WebElement> visibilityOfAnyElementLocated(final By locator) {
    return new Coordinator<WebElement>() {

        @Override
        public WebElement apply(SearchContext context) {
            try {
                List<WebElement> visible = context.findElements(locator);
                return (WebDriverUtils.filterHidden(visible)) ? null : visible.get(0);
            } catch (StaleElementReferenceException e) {
                return null;
            }
        }

        @Override
        public String toString() {
            return "visibility of element located by " + locator;
        }
    };

}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:27,代碼來源:Coordinators.java

示例2: selectAction

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
@Override
protected void selectAction(String name) {
    expandAction();
    String[] nodes = name.split(" > ");
    SearchContext context = getDriver();
    if (treeLocators.size() < nodes.length) return;
    for(int i=0; i < nodes.length; i++) {
        String value = nodes[i];
        List<WebElement> els = context.findElements(correctXPaths(treeLocators.get(i)));
        if (els.size() == 0)
            throw exception("No elements found for locator: " + treeLocators.get(i) + "in TreeDropdown " + this);
        context = first(els, el -> el.getText().equals(value));
        if (context == null)
            throw exception("Can't find: " + value + "in TreeDropdown " + this);
        if (i < nodes.length - 1) {
            int next = i + 1;
            boolean nextValue =
                    LinqUtils.any(context.findElements(correctXPaths(treeLocators.get(next))), el -> el.getText().equals(nodes[next]));
            if (nextValue) continue;
        }
        ((WebElement) context).click();
    }
}
 
開發者ID:epam,項目名稱:JDI,代碼行數:24,代碼來源:TreeDropdown.java

示例3: findElement

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
@Override
public WebElement findElement(SearchContext driver)
{
	String attrName = getAttrName();
	String attrVal = getValue();
	By by = getBy();

	List<WebElement> elementList = driver.findElements(by);
	for(WebElement ele : elementList)
	{
		if(driver instanceof WebDriver)
		{
			new Actions((WebDriver) driver).moveToElement(ele);
		}
		
		if(attrVal.equals(ele.getAttribute(attrName)))
		{
			return ele;
		}
	}
	
	return null;
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:24,代碼來源:AbstractSeleniumAttrLocator.java

示例4: findElements

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public List<E> findElements(SearchContext driver)
{
	By by = getBy();
	
	if(driver instanceof WebDriver)
	{
		elementWait((WebDriver) driver, getTimeout(), by);
	}
	
	return (List<E>) driver.findElements(by);
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:13,代碼來源:AbstractLocator.java

示例5: findOrNull

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Return the first element matched by the selector, or null if not found
 * @param from a WebElement to start the search from, or the WebDriver to search in all the page
 * @param by
 * @return
 */
public WebElement findOrNull(SearchContext from, By by) {
	List<WebElement> webElements = from.findElements(by);
	if (webElements.isEmpty()) {
		return null;
	}
	return webElements.get(0);
}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:14,代碼來源:YadaSeleniumUtil.java

示例6: if

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
public static List<WebElement> $$(final SearchContext context, final String selector, final Predicate<WebElement> predicate) {
    List<WebElement> elements;
    if (byId(selector)) {
        elements = context.findElements(By.id(selector.substring(1)));
    }
    else if (byName(selector)) {
        elements = context.findElements(By.name(selector.substring(1)));
    }
    else if (byXpath(selector)) {
        elements = context.findElements(By.xpath(selector));
    }
    else if (byLinkText(selector)) {
        elements = context.findElements(By.linkText(selector.substring(1)));
    }
    else {
        elements = context.findElements(By.cssSelector(selector));
    }
    
    if(elements == null || elements.isEmpty()) {
        throw new ElementNotFoundException(selector);
    }
    
    final List<WebElement> filteredElements = elements.stream()
                .filter(Optional.ofNullable(predicate).orElse(Objects::nonNull))
                .collect(Collectors.toList());
    
    if(filteredElements.isEmpty()) {
        throw new ElementNotFoundException(selector, elements);
    }
    
    return filteredElements;
}
 
開發者ID:codezombies,項目名稱:easytest,代碼行數:33,代碼來源:Selectors.java

示例7: searchElements

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private List<WebElement> searchElements()
{
    SearchContext searchContext = containsRoot(getLocator())
            ? getDriver()
            : getSearchContext(element.getParent());
    By locator = containsRoot(getLocator())
            ? trimRoot(getLocator())
            : getLocator();
    if (frameLocator != null)
        getDriver().switchTo().frame((WebElement)getDriver().findElement(frameLocator));
    return searchContext.findElements(correctXPaths(locator));
}
 
開發者ID:epam,項目名稱:JDI,代碼行數:13,代碼來源:GetElementModule.java

示例8: findVisibleElements

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 *
 * @param sc
 * @param by
 * @return
 */
public static List<WebElement> findVisibleElements(SearchContext sc, By by) {
      List<WebElement> elements = sc.findElements(by);
      Iterator<WebElement> it = elements.iterator();
      while (it.hasNext()) {
          WebElement el = it.next();
          if (!el.isDisplayed()) {
              it.remove();
          }
      }
      return elements;
  }
 
開發者ID:BenjaminLimb,項目名稱:web-test-framework,代碼行數:18,代碼來源:SeleniumHelperUtil.java

示例9: checkOutOfViewClass

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private void checkOutOfViewClass(final SearchContext widget) {
    final List<WebElement> results = widget.findElements(By.cssSelector(".search-result"));

    results.forEach(result -> {
        final boolean isDisplayed = result.isDisplayed();
        final boolean hasClass = result.getAttribute("class").contains("out-of-view");

        assertTrue(
                "All invisible results (and only invisible results) must have the out-of-view class",
                isDisplayed ^ hasClass
        );
    });
}
 
開發者ID:hpe-idol,項目名稱:find,代碼行數:14,代碼來源:ResultsListWidgetITCase.java

示例10: findElement

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Returns 'best' result from by.
 * If there is no result: returns null,
 * if there is just one that is best,
 * otherwise the 'bestFunction' is applied to all results to determine best.
 * @param by by to use to find elements.
 * @param context context to search in.
 * @param <T> type of element expected.
 * @return 'best' element, will be <code>null</code> if no elements were found.
 */
public static <T extends WebElement> T findElement(By by, SearchContext context) {
    WebElement element = null;
    List<WebElement> elements = context.findElements(by);
    if (elements.size() == 1) {
        element = elements.get(0);
    } else if (elements.size() > 1) {
        element = BEST_FUNCTION.apply(context, elements);
    }
    return (T) element;
}
 
開發者ID:fhoeben,項目名稱:hsac-fitnesse-fixtures,代碼行數:21,代碼來源:BestMatchBy.java

示例11: locate

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
@Override
public List<WebElement> locate(SearchContext t) {
    logger.info("Seeking elements [{}]", by);
    List<WebElement> elements = t.findElements(by);
    logger.info("Found [{}]", elements);
    return elements.stream().map(Element::new).collect(toList());
}
 
開發者ID:yujunliang,項目名稱:seleniumcapsules,代碼行數:8,代碼來源:ElementsFinder.java

示例12: findElement

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
@Override
public WebElement findElement(SearchContext driver)
{
	final String priorityCss; //優先定位的css值
	final String targetCss;
	final String css = getValue();
	
	String[] priorityCssArray = css.split(",");
	if(priorityCssArray.length >= 2)
	{
		targetCss = priorityCssArray[1];
		priorityCss = priorityCssArray[0];
	}
	else
	{
		targetCss = css;
		priorityCss = css.split(" ")[0];
	}
	
	//設定當前的定位器
	setValue(priorityCss);
	By by = getBy();
	
	//值還原
	setValue(css);
	List<WebElement> elementList = driver.findElements(by);
	for(WebElement ele : elementList)
	{
		if(driver instanceof WebDriver)
		{
			new Actions((WebDriver) driver).moveToElement(ele);
		}
		
		if(targetCss.equals(ele.getAttribute("class")))
		{
			return ele;
		}
	}
	
	return null;
}
 
開發者ID:LinuxSuRen,項目名稱:phoenix.webui.framework,代碼行數:42,代碼來源:SeleniumCssLocator.java

示例13: acquireReference

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Acquire the element reference that's wrapped by the specified robust element wrapper.
 * 
 * @param wrapper robust element wrapper
 * @return wrapped element reference
 */
private static RobustElementWrapper acquireReference(RobustElementWrapper wrapper) {
    SearchContext context = wrapper.context.getWrappedContext();
    
    if (wrapper.strategy == Strategy.LOCATOR) {
        Timeouts timeouts = wrapper.driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
        try {
            if (wrapper.index > 0) {
                List<WebElement> elements = context.findElements(wrapper.locator);
                if (wrapper.index < elements.size()) {
                    wrapper.wrapped = elements.get(wrapper.index);
                } else {
                    throw new NoSuchElementException(
                            String.format("Too few elements located %s: need: %d; have: %d", 
                                    wrapper.locator, wrapper.index + 1, elements.size()));
                }
            } else {
                wrapper.wrapped = context.findElement(wrapper.locator);
            }
        } catch (NoSuchElementException e) {
            if (wrapper.index != OPTIONAL) {
                throw e;
            }
            
            wrapper.deferredException = e;
            wrapper.wrapped = null;
        } finally {
            timeouts.implicitlyWait(WaitType.IMPLIED.getInterval(), TimeUnit.SECONDS);
        }
    } else {
        List<Object> args = new ArrayList<>();
        List<WebElement> contextArg = new ArrayList<>();
        if (context instanceof WebElement) {
            contextArg.add((WebElement) context);
        }
        
        String js;
        args.add(contextArg);
        args.add(wrapper.selector);
        
        if (wrapper.strategy == Strategy.JS_XPATH) {
            js = LOCATE_BY_XPATH;
        } else {
            js = LOCATE_BY_CSS;
            args.add(wrapper.index);
        }
        
        wrapper.wrapped = JsUtility.runAndReturn(wrapper.driver, js, args.toArray());
    }
    
    if (wrapper.wrapped != null) {
        wrapper.acquiredAt = System.currentTimeMillis();
        wrapper.deferredException = null;
    }
    
    return wrapper;
}
 
開發者ID:Nordstrom,項目名稱:Selenium-Foundation,代碼行數:63,代碼來源:RobustElementFactory.java

示例14: findElements

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
@Override public List<WebElement> findElements(SearchContext context) {
    return context.findElements(map.get(WebDriverUnpackUtility.getCurrentContentType(context)));
}
 
開發者ID:JoeUtt,項目名稱:menggeqa,代碼行數:4,代碼來源:ContentMappedBy.java

示例15: searchElements

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private List<WebElement> searchElements() {
    SearchContext searchContext = getDefaultContext();
    if (!containsRoot(getLocator()))
        searchContext = getSearchContext(element.getParent());
    return searchContext.findElements(correctLocator(getLocator()));
}
 
開發者ID:epam,項目名稱:JDI,代碼行數:7,代碼來源:GetElementModule.java


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