當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。