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


Java SearchContext.findElement方法代碼示例

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


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

示例1: getSearchContext

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private SearchContext getSearchContext(Object element) {
    if (element == null || !isClass(element.getClass(), BaseElement.class))
        return getDefaultContext();
    BaseElement bElement = (BaseElement) element;
    if (bElement.useCache && isClass(bElement.getClass(), Element.class)) {
        Element el = (Element) bElement;
        if (el.avatar.hasWebElement())
            return el.avatar.webElement;
    }
    Object p = bElement.getParent();
    By locator = bElement.getLocator();
    By frame = bElement.avatar.frameLocator;
    SearchContext searchContext = frame != null
        ? getFrameContext(frame)
        : p == null || containsRoot(locator)
            ? getDefaultContext()
            : getSearchContext(p);
    return locator != null
            ? searchContext.findElement(correctLocator(locator))
            : searchContext;
}
 
開發者ID:epam,項目名稱:JDI,代碼行數:22,代碼來源:GetElementModule.java

示例2: getSearchContext

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private SearchContext getSearchContext(Object element) {
    Object p;
    BaseElement bElement;
    Element el;
    if (element == null || !isClass(element.getClass(), BaseElement.class)
            || ((p = (bElement = (BaseElement) element).getParent()) == null
            && bElement.avatar.frameLocator == null))
        return getDriver().switchTo().defaultContent();
    if (isClass(bElement.getClass(), Element.class) && (el = (Element) bElement).avatar.hasWebElement())
        return el.getWebElement();
    By locator = bElement.getLocator();
    SearchContext searchContext = containsRoot(locator)
            ? getDriver().switchTo().defaultContent()
            : getSearchContext(p);
    locator = containsRoot(locator)
            ? trimRoot(locator)
            : locator;
    By frame = bElement.avatar.frameLocator;
    if (frame != null)
        getDriver().switchTo().frame((WebElement)getDriver().findElement(frame));
    return locator != null
            ? searchContext.findElement(correctXPaths(locator))
            : searchContext;
}
 
開發者ID:epam,項目名稱:JDI,代碼行數:25,代碼來源:GetElementModule.java

示例3: findElement

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

示例4: findElementByPartialText

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
public static final WebElement findElementByPartialText(SearchContext context, String tag, String... partialTexts) {
	String xpath = "//" + tag + "[1=1";
	for (String text : partialTexts) {
		xpath += " and contains(text(), '" + text + "')";
	}
	xpath += "]";
	return context.findElement(By.xpath(xpath));
}
 
開發者ID:21ca,項目名稱:selenium-testng-template,代碼行數:9,代碼來源:SeleniumUtils.java

示例5: getTextIfExists

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Search for text
 * @param from a WebElement to start the search from, or the WebDriver to search in all the page
 * @param by
 * @return the text found, or ""
 */
public String getTextIfExists(SearchContext from, By by) {
	try {
		WebElement webElement = from.findElement(by);
		return webElement.getText();
	} catch (Exception e) {
		return "";
	}
}
 
開發者ID:xtianus,項目名稱:yadaframework,代碼行數:15,代碼來源:YadaSeleniumUtil.java

示例6: findElement

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Constructs a scope out of the scope factory and the parent field, then searches for field with
 * selector in this scope.
 */
@Override
public WebElement findElement() {

  SearchContext context =
      scopeFactory instanceof ParentElementLocatorProvider && !globalCurrentScope
          ? ((ParentElementLocatorProvider) scopeFactory).getCurrentScope().findElement()
          : searchContext;
  return context.findElement(selector);
}
 
開發者ID:Cognifide,項目名稱:bobcat,代碼行數:14,代碼來源:NestedSelectorScopedElementLocator.java

示例7: rootElement

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
protected WebElement rootElement() {
    SearchContext ctx = rootSearchContextSupplier.get();
    if (ctx instanceof WebElement)
        return (WebElement) ctx;
    else if (ctx instanceof WebDriver)
        return ctx.findElement(By.cssSelector("html"));
    throw new RuntimeException("Unable to determine root element for search context " + ctx);
}
 
開發者ID:ruediste,項目名稱:rise,代碼行數:9,代碼來源:PageObject.java

示例8: getSearchContext

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private SearchContext getSearchContext(Object element) {
    if (element == null || !(element instanceof BaseElement))
        return getDriver();

    BaseElement bElement = (BaseElement) element;
    By locator = bElement.getAvatar().getByLocator();

    SearchContext searchContext = getSearchContext(bElement.getParent());

    return locator != null
            ? searchContext.findElement(locator)
            : searchContext;
}
 
開發者ID:epam,項目名稱:JDI,代碼行數:14,代碼來源:GetElementModule.java

示例9: getSearchContext

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private SearchContext getSearchContext(Pairs<ContextType, By> context) {
    SearchContext searchContext = getDriver().switchTo().defaultContent();
    for (Pair<ContextType, By> locator : context) {
        WebElement element = searchContext.findElement(locator.value);
        if (locator.key == ContextType.Locator)
            searchContext = element;
        else {
            getDriver().switchTo().frame(element);
            searchContext = getDriver();
        }
    }
    return searchContext;
}
 
開發者ID:ggasoftware,項目名稱:gga-selenium-framework,代碼行數:14,代碼來源:GetElementModule.java

示例10: 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

示例11: findWebElement

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
private WebElement findWebElement() {
    SearchContext searchContext = model.getSearchContext();
    return searchContext.findElement(model.getSeleniumBy());
}
 
開發者ID:testIT-WebTester,項目名稱:webtester-core,代碼行數:5,代碼來源:PageObject.java

示例12: waitForElement

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Waits for the presence of a specific web element until a timeout is reached. The method will succeed in any case.
 * If the element is not present, the method waits until the timeout, otherwise it returns as soon as the element is
 * present
 *
 * @param context
 *         the search context in which the element should be located
 * @param by
 *         the locate for the element
 * @param waitSec
 *         the timeout in seconds
 *
 * @return the located element
 */
public static WebElement waitForElement(final SearchContext context, final By by, final int waitSec) {

    new FluentWait<>(context).ignoring(NoSuchElementException.class)
                             .withTimeout(waitSec, TimeUnit.SECONDS)
                             .until((Predicate<SearchContext>) d -> context.findElement(by).isDisplayed());
    return context.findElement(by);

}
 
開發者ID:devcon5io,項目名稱:pageobjects,代碼行數:23,代碼來源:WebElementLocator.java

示例13: assertEnabled

import org.openqa.selenium.SearchContext; //導入方法依賴的package包/類
/**
 * Helper method to verify if a button is enabled
 * @param parent The parent of the button
 * @param className The class name used to look it up in the parent
 * @param enabled true if the button should be enabled, false if it should be disabled
 */
private void assertEnabled(SearchContext parent, String className, boolean enabled) {
    WebElement btn = parent.findElement(By.className(className));
    Assert.assertEquals(btn.isEnabled(), enabled);
}
 
開發者ID:Comcast,項目名稱:dawg,代碼行數:11,代碼來源:AdvanceFilterNavigator.java


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