当前位置: 首页>>代码示例>>Java>>正文


Java WebDriver.findElements方法代码示例

本文整理汇总了Java中org.openqa.selenium.WebDriver.findElements方法的典型用法代码示例。如果您正苦于以下问题:Java WebDriver.findElements方法的具体用法?Java WebDriver.findElements怎么用?Java WebDriver.findElements使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openqa.selenium.WebDriver的用法示例。


在下文中一共展示了WebDriver.findElements方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visibilityOfNbElementsLocatedBy

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * An expectation for checking that nb elements present on the web page that match the locator
 * are visible. Visibility means that the elements are not only displayed but also have a height
 * and width that is greater than 0.
 *
 * @param locator
 *            used to find the element
 * @param nb
 *            is exactly number of responses
 * @return the list of WebElements once they are located
 */
public static ExpectedCondition<List<WebElement>> visibilityOfNbElementsLocatedBy(final By locator, final int nb) {
    return new ExpectedCondition<List<WebElement>>() {
        @Override
        public List<WebElement> apply(WebDriver driver) {
            int nbElementIsDisplayed = 0;
            final List<WebElement> elements = driver.findElements(locator);
            for (final WebElement element : elements) {
                if (element.isDisplayed()) {
                    nbElementIsDisplayed++;
                }
            }
            return nbElementIsDisplayed == nb ? elements : null;
        }
    };
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:27,代码来源:Utilities.java

示例2: findElements

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static List<WebElement> findElements( UiElement uiElement, String xpathSuffix, boolean verbose ) {

        AbstractRealBrowserDriver browserDriver = (AbstractRealBrowserDriver) uiElement.getUiDriver();
        WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
        HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);

        String xpath = uiElement.getElementProperties()
                                .getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);

        String css = uiElement.getElementProperty("_css");

        if (xpathSuffix != null) {
            xpath += xpathSuffix;
        }

        if (!StringUtils.isNullOrEmpty(css)) {
            return webDriver.findElements(By.cssSelector(css));
        } else {
            return webDriver.findElements(By.xpath(xpath));
        }

    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:23,代码来源:RealHtmlElementLocator.java

示例3: assertLoaded

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
@Override
public void assertLoaded(final WebDriver driver) {
    if (!isValidationOn()) {
        return;
    }

    final List<WebElement> foundEvilWords = driver.findElements(evilWordsLocator);
    if (isNotEmpty(foundEvilWords)) {
        LOGGER.error("Unexpected evil word found. Pages source:\n" + driver.getPageSource());
        lookForConcreteEvilWord(driver);
        fail("oops! I found evil word, but didn't find element with it");
    }
}
 
开发者ID:WileyLabs,项目名称:teasy,代码行数:14,代码来源:WordsBasedPageLoadingValidator.java

示例4: findElements

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * 查找多个元素
 * @param by
 * @return
 */
private List<WebElement> findElements(By by)
{
	WebDriver driver = engine.getDriver();
	driver = engine.turnToRootDriver(driver);
	
	if(parentElement != null)
	{
		return parentElement.findElements(by);
	}
	else
	{
		return driver.findElements(by);
	}
}
 
开发者ID:LinuxSuRen,项目名称:phoenix.webui.framework,代码行数:20,代码来源:PrioritySearchStrategy.java

示例5: presenceOfNbElementsLocatedBy

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * An expectation for checking that there is at least one element present on a web page.
 *
 * @param locator
 *            used to find the element
 * @param nb
 *            is exactly number of responses
 * @return the list of WebElements once they are located
 */
public static ExpectedCondition<List<WebElement>> presenceOfNbElementsLocatedBy(final By locator, final int nb) {
    return new ExpectedCondition<List<WebElement>>() {
        @Override
        public List<WebElement> apply(WebDriver driver) {
            final List<WebElement> elements = driver.findElements(locator);
            return elements.size() == nb ? elements : null;
        }
    };
}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:19,代码来源:Utilities.java

示例6: findElement

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static WebElement findElement( UiElement uiElement, String xpathSuffix, boolean verbose ) {

        AbstractRealBrowserDriver browserDriver = (AbstractRealBrowserDriver) uiElement.getUiDriver();
        WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
        HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);

        String xpath = uiElement.getElementProperties()
                                .getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);

        String css = uiElement.getElementProperty("_css");

        if (xpathSuffix != null) {
            xpath += xpathSuffix;
        }

        List<WebElement> elements = null;

        if (!StringUtils.isNullOrEmpty(css)) {
            elements = webDriver.findElements(By.cssSelector(css));
        } else {
            elements = webDriver.findElements(By.xpath(xpath));
        }

        if (elements.size() == 0) {
            throw new ElementNotFoundException(uiElement.toString() + " not found.");
        } else if (elements.size() > 1) {
            if (verbose) {

                log.warn("More than one HTML elements were found having properties " + uiElement.toString()
                         + ".Only the first HTML element will be used.");

            }
        }
        WebElement element = (WebElement) elements.get(0);
        if (verbose) {

            log.debug("Found element: " + element.toString());
        }
        return element;
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:41,代码来源:RealHtmlElementLocator.java

示例7: test

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
static void test() {
	System.setProperty("webdriver.chrome.driver", "D:\\selenium\\chromedriver_win32\\chromedriver.exe");
	
	WebDriver driver = new ChromeDriver();
	
	driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
	driver.manage().timeouts().pageLoadTimeout(5, TimeUnit.SECONDS);
	
	String url = "http://www.baidu.com/";

	driver.get(url);
		
		//��ȡ��ǰҳ��ȫ��iframe������iframe����Ԫ��
		try {
			List<WebElement> iframes = driver.findElements(By.tagName("iframe")); //��ȡȫ��iframe��ǩ
			if(iframes.size()!=0) {
				for(WebElement iframe : iframes) {
					if(iframe.getSize() != null) {
						  System.out.println(iframe.getAttribute("outerHtml"));
					}
				}
			}else{
				System.out.println("��ҳ�治����iframe");
			}				
		}catch(Exception e) {
			System.out.println(e);
		}
	
}
 
开发者ID:Yinqingseu,项目名称:SeleniumTest,代码行数:30,代码来源:WebdriverTest.java

示例8: esperaCargaPaginaxpath

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
static public List<WebElement> esperaCargaPaginaxpath(WebDriver driver, String xpath, int timeout)
{
	WebElement resultado = 
			(new WebDriverWait(driver, timeout)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
	assertTrue(resultado != null);
	List<WebElement> elementos = driver.findElements(By.xpath(xpath));

			return elementos;					
}
 
开发者ID:Arquisoft,项目名称:dashboard1b,代码行数:10,代码来源:SeleniumUtils.java

示例9: EsperaCargaPaginaxpath

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
static public List<WebElement> EsperaCargaPaginaxpath(WebDriver driver, String xpath, int timeout) {
	WebElement resultado = (new WebDriverWait(driver, timeout))
			.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
	assertTrue(resultado != null);
	List<WebElement> elementos = driver.findElements(By.xpath(xpath));

	return elementos;
}
 
开发者ID:Arquisoft,项目名称:dashboard1b,代码行数:9,代码来源:SeleniumUtils.java

示例10: getElementByName

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public WebElement getElementByName(String elementName, int nth, WebDriver webDriver) {
    List<WebElement> elements = webDriver.findElements(pageElements.get(elementName));

    if (elements.size() == 0) {
        return null;
    }

    return elements.get(nth);
}
 
开发者ID:NHS-digital-website,项目名称:hippo,代码行数:10,代码来源:PublicationPageElements.java

示例11: EsperaCargaPaginaxpath

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
static public List<WebElement> EsperaCargaPaginaxpath(WebDriver driver, String xpath, int timeout)
{
	WebElement resultado = 
			(new WebDriverWait(driver, timeout)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xpath)));
	assertTrue(resultado != null);
	List<WebElement> elementos = driver.findElements(By.xpath(xpath));
	
	return elementos;					
}
 
开发者ID:Arquisoft,项目名称:participationSystem3b,代码行数:10,代码来源:SeleniumUtils.java

示例12: textoPresentePagina

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
static public void textoPresentePagina(WebDriver driver, String texto) {
	List<WebElement> list = driver.findElements(By.xpath("//*[contains(text(),'" + texto + "')]"));
	assertTrue("Texto " + texto + " no localizado!", list.size() > 0);
}
 
开发者ID:Arquisoft,项目名称:dashboard1b,代码行数:5,代码来源:SeleniumUtils.java

示例13: textoNoPresentePagina

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
static public void textoNoPresentePagina(WebDriver driver, String texto) {
	List<WebElement> list = driver.findElements(By.xpath("//*[contains(text(),'" + texto + "')]"));
	assertTrue("Texto " + texto + " aun presente !", list.size() == 0);
}
 
开发者ID:Arquisoft,项目名称:dashboard1b,代码行数:5,代码来源:SeleniumUtils.java

示例14: isElementPresentAndGetFirstOne

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
/**
 * Check if element present and get first one.
 *
 * @param element
 *            is {link org.openqa.selenium.By} find in page.
 * @return first {link org.openqa.selenium.WebElement} finded present element.
 */
public static WebElement isElementPresentAndGetFirstOne(By element) {

    final WebDriver webDriver = Context.getDriver();

    webDriver.manage().timeouts().implicitlyWait(DriverFactory.IMPLICIT_WAIT * 2, TimeUnit.MICROSECONDS);

    final List<WebElement> foundElements = webDriver.findElements(element);
    final boolean exists = !foundElements.isEmpty();

    webDriver.manage().timeouts().implicitlyWait(DriverFactory.IMPLICIT_WAIT, TimeUnit.MICROSECONDS);

    if (exists) {
        return foundElements.get(0);
    } else {
        return null;
    }

}
 
开发者ID:NoraUi,项目名称:NoraUi,代码行数:26,代码来源:Utilities.java

示例15: findElement

import org.openqa.selenium.WebDriver; //导入方法依赖的package包/类
public static HtmlUnitWebElement findElement( UiElement uiElement, String xpathSuffix, boolean verbose ) {

        HiddenBrowserDriver browserDriver = (HiddenBrowserDriver) uiElement.getUiDriver();
        WebDriver webDriver = (WebDriver) browserDriver.getInternalObject(InternalObjectsEnum.WebDriver.name());
        HtmlNavigator.getInstance().navigateToFrame(webDriver, uiElement);

        String xpath = uiElement.getElementProperties()
                                .getInternalProperty(HtmlElementLocatorBuilder.PROPERTY_ELEMENT_LOCATOR);

        String css = uiElement.getElementProperty("_css");

        if (xpathSuffix != null) {
            xpath += xpathSuffix;
        }

        List<WebElement> elements = null;

        if (!StringUtils.isNullOrEmpty(css)) {
            elements = webDriver.findElements(By.cssSelector(css));
        } else {
            elements = webDriver.findElements(By.xpath(xpath));
        }

        if (elements.size() == 0) {

            throw new ElementNotFoundException(uiElement.toString() + " not found.");
        } else if (elements.size() > 1) {
            if (verbose) {

                log.warn("More than one HTML elements were found having properties " + uiElement.toString()
                         + ".Only the first HTML element will be used.");

            }
        }
        HtmlUnitWebElement element = (HtmlUnitWebElement) elements.get(0);
        if (verbose) {

            log.info("Found element: " + element.toString());
        }
        return element;
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:42,代码来源:HiddenHtmlElementLocator.java


注:本文中的org.openqa.selenium.WebDriver.findElements方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。