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


Java WebElement.findElements方法代码示例

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


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

示例1: all

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public Contacts all() {
    if (contactCache != null) {
        return new Contacts(contactCache);
    }
    contactCache = new Contacts();
    List<WebElement> elements = wd.findElements(By.xpath("//tr[@name='entry']"));
    for (WebElement element : elements) {
        List<WebElement> contactEntries = element.findElements(By.cssSelector("td"));
        String firstname = contactEntries.get(2).getText();
        String lastname = contactEntries.get(1).getText();
        String allPhones = contactEntries.get(5).getText();
        String allEmails = contactEntries.get(4).getText();
        String address = contactEntries.get(3).getText();
        int id = Integer.parseInt(element.findElement(By.tagName("input")).getAttribute("value"));
        contactCache.add(new ContactData().withId(id).withFirstname(firstname).withLastname(lastname)
                .withAllPhones(allPhones).withAllEmails(allEmails).withAddress(address));
    }
    return new Contacts(contactCache);
}
 
开发者ID:LadyTurandot,项目名称:Java_Good,代码行数:20,代码来源:ContactHelper.java

示例2: checkTableHasRows

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Checks whether a table, identified by having a heading with the specified text, has at least the specified
 * number of rows (ignoring any heading rows).
 * @param headingText       The table heading text to look for
 * @param rows              The minimum number of rows the table must have
 * @return <code>true</code> if the table has at least <code>rows</code> rows.
 */
public boolean checkTableHasRows(String headingText, int rows) {
    try {
        // find the table with a heading containing the specified text...
        WebElement tableElement = webDriver.findElement(
                By.xpath("//th[contains(text(),'" + headingText + "')]//ancestor::table[1]"));

        // then count the number of rows in the table...
        List<WebElement> rowElements = tableElement.findElements(By.tagName("tr"));

        // is the number of rows (minus the heading row) at lest the specified amount?
        return (rowElements.size() - 1) >= rows;

    } catch (NoSuchElementException ex) {
        return false;
    }
}
 
开发者ID:dvsa,项目名称:mot-automated-testsuite,代码行数:24,代码来源:WebDriverWrapper.java

示例3: getCellValue

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public HashMap<String, String> getCellValue(WebElement Element, int tr,
        int td) {
    int rowCounter = 0;
    int colCounter = 0;
    String rowKey = null;
    String colKey = null;
    HashMap<String, String> HashTable = new HashMap<>();

    String strObj = Data;
    List<WebElement> tableList = Element.findElements(By
            .cssSelector("div[class='" + strObj + "'] tr td"));
    for (WebElement listIterator : tableList) {
        String TagName = listIterator.getTagName();
        if (TagName.equals("tr")) {
            rowKey = "R" + rowCounter++;
        }
        if (TagName.equals("td")) {
            colKey = "C" + colCounter++;
        }
        HashTable.put(rowKey + colKey, listIterator.getText());
    }
    return HashTable;
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:24,代码来源:CommonMethods.java

示例4: typeInElement

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * @category Set Element
 */
private void typeInElement(WebElement element, String content) {
	_action.moveToElement(element);
	switch (this.getFieldType(element)) {
	case "choice":
		List<WebElement> options = element.findElements(By.tagName("option"));
		for (int i = 0; i < options.size(); i++) {
			if (options.get(i).getText().trim().equalsIgnoreCase(content)) {
				element.click();
				options.get(i).click();
				break;
			}
		}
		break;
	default:
		_action.click();
		if(!this.getFieldValueByID(element.getAttribute("id")).equalsIgnoreCase("")) {
			//TODO - Find a faster way to do this.
			_action.sendKeys(Keys.END);
			for (int i = 0; i <this.getFieldValueByID(element.getAttribute("id")).length(); i ++) {
				_action.sendKeys(Keys.BACK_SPACE);
			}

		}
		_action.sendKeys(content);
		_action.sendKeys(Keys.TAB);
	_action.perform();
	}

}
 
开发者ID:SeanABoyer,项目名称:ServiceNow_Selenium,代码行数:33,代码来源:ServiceNow.java

示例5: getTableRowByColumnText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
 * Example: getRowTextsByColumnText(table, 2, '22') returns row {11, 22, 33}
    * 1	2	3
    * 11	22	33
    * 111	222	333
 * 
 * @param table
 * @param columnIndex Start from 1
 * @param searchText
 * @return
 */
public static final List<String> getTableRowByColumnText(WebElement table, int columnIndex, String searchText) {
	if (!table.getTagName().equalsIgnoreCase("table")) {
   		throw new IllegalArgumentException("Table web element is required");
   	}

	WebElement rowElement = table.findElement(By.xpath("//tr//td[position()=" + columnIndex + " and contains(*|text(), '" + searchText + "')]/.."));
   	List<WebElement> elements = rowElement.findElements(By.tagName("td"));
   	List<String> result = new ArrayList<String>(elements.size());
   	for (WebElement e : elements) {
   		result.add(StringUtils.trim(e.getText()));
   	}
   	return result;
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:25,代码来源:SeleniumUtils.java

示例6: getAllNodes

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void getAllNodes() throws Throwable {
    expandTree();
    WebElement tree = page.getTree();
    tree.click();
    List<WebElement> nodes = tree.findElements(By.cssSelector(".::all-nodes"));
    AssertJUnit.assertEquals(7, nodes.size());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:8,代码来源:JTreeDynamicTreeTest.java

示例7: getNodesByText

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void getNodesByText() throws Throwable {
    WebElement tree = page.getTree();
    tree.click();
    AssertJUnit.assertEquals("[\"Root Node\"]", tree.getText());
    expandTree();
    AssertJUnit.assertEquals("[\"Root Node\",\"Parent 1\",\"Child 1\",\"Child 2\",\"Parent 2\",\"Child 1\",\"Child 2\"]",
            tree.getText());
    List<WebElement> nodes;
    nodes = tree.findElements(By.cssSelector(".::all-nodes[text='Root Node']"));
    AssertJUnit.assertEquals(1, nodes.size());
    nodes = tree.findElements(By.cssSelector(".::all-nodes[text='Child 2']"));
    AssertJUnit.assertEquals(2, nodes.size());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JTreeDynamicTreeTest.java

示例8: listGetAnItemFromListWebelement

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void listGetAnItemFromListWebelement() throws Throwable {
    driver = new JavaDriver();
    WebElement list = driver.findElement(By.name("list-1"));
    WebElement item21 = list.findElement(By.cssSelector(".::nth-item(21)"));
    assertEquals("List Item - 21", item21.getText());
    List<WebElement> allItems = list.findElements(By.cssSelector(".::all-items"));
    assertEquals(30, allItems.size());
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:9,代码来源:JListXTest.java

示例9: findElementsOfElement

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public void findElementsOfElement() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element = driver.findElement(By.name("box-panel"));
    AssertJUnit.assertNotNull(element);
    List<WebElement> clickMe = element.findElements(By.name("click-me"));
    AssertJUnit.assertNotNull(clickMe);
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:JavaDriverTest.java

示例10: getOppositeUser

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
private static String getOppositeUser(String transactionNo) {
	// ��ȡ�ؼ��ֶ�Ӧ��������
	WebElement keywordInput = driver.findElement(By.id("J-keyword"));
	keywordInput.clear();
	keywordInput.sendKeys(transactionNo);
	WebElement keywordSelect = driver.findElement(By.id("keyword"));
	List<WebElement> options = keywordSelect.findElements(By.tagName("option"));
	// until������ʾֱ���ɵ��ٵ�
	// WebElement selectElement = wait.until(ExpectedConditions
	// .visibilityOfElementLocated(By.id("keyword")));
	// ��Ҫִ��JavaScript��䣬����ǿתdriver
	JavascriptExecutor js = (JavascriptExecutor) driver;
	// Ҳ������ô��setAttribute("style","");
	js.executeScript("document.getElementById('keyword').style.display='list-item';");
	js.executeScript("document.getElementById('keyword').removeAttribute('smartracker');");
	js.executeScript("document.getElementById('keyword').options[1].selected = true;");
	js.executeScript("document.getElementById('J-select-range').style.display='list-item';");
	// ���ý���ʱ��ѡ��
	Select selectTime = new Select(driver.findElement(By.id("J-select-range")));
	selectTime.selectByIndex(3);// ѡ�е������������
	System.out.println("selectTime.isMultiple() : " + selectTime.isMultiple());
	// ���ùؼ���ѡ��
	Select selectKeyword = new Select(driver.findElement(By.id("keyword")));
	// selectKeyword.selectByValue("bizInNo");//�˴���value��д<option>��ǩ�е�valueֵ
	selectKeyword.selectByIndex(1);// ѡ�е��ǽ��׺�
	System.out.println("selectKeyword.isMultiple() : " + selectKeyword.isMultiple());
	WebElement queryButton = driver.findElement(By.id("J-set-query-form"));// �õ�������ť
	// ���������ť
	queryButton.submit();
	WebElement tr = driver.findElement(By.id("J-item-1"));// �Ȼ�ȡtr
	WebElement td = tr.findElement(By.xpath("//*[@id=\"J-item-1\"]/td[5]/p[1]"));
	return td.getText();
}
 
开发者ID:qwl-nju,项目名称:AlipayAuto,代码行数:34,代码来源:AlipayAuto.java

示例11: getTableTextsByColumnIndex

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
    * Example: getTableTextsByColumnIndex(table, 2) returns {2, 22, 22}
    * 1	2	3
    * 11	22	33
    * 111	222	333
    * 
    * @param tablert5
    * @return
    */
public static final List<String> getTableTextsByColumnIndex(WebElement table, int columnIndex) {
   	if (!table.getTagName().equalsIgnoreCase("table")) {
   		throw new IllegalArgumentException("Table web element is required");
   	}
   	
   	List<WebElement> elements = table.findElements(By.cssSelector("tr td:nth-child(" + columnIndex + ")"));
   	List<String> result = new ArrayList<String>(elements.size());
   	for (WebElement e : elements) {
   		result.add(StringUtils.trim(e.getText()));
   	}
   	return result;
   }
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:22,代码来源:SeleniumUtils.java

示例12: unselectCheckbox

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public static final void unselectCheckbox(WebElement parent, int index){
	List<WebElement> checkBox= parent.findElements(By.cssSelector("input[type='checkbox']"));
	if(checkBox.get(index).isSelected()){
		checkBox.get(index).click();
		SeleniumUtils.sleepInSeconds(2);
	}
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:8,代码来源:SeleniumUtils.java

示例13: getTableTextsByRowIndex

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
/**
    * Example: getTableTextsByRowIndex(table, 2) returns {11, 22, 33}
    * 1	2	3
    * 11	22	33
    * 111	222	333
    * 
    * @param table
    * @param rowIndex Start from 1.
    * @return
    */
public static final List<String> getTableTextsByRowIndex(WebElement table, int rowIndex) {
   	if (!table.getTagName().equalsIgnoreCase("table")) {
   		throw new IllegalArgumentException("Table web element is required");
   	}
   	
   	List<WebElement> elements = table.findElements(By.cssSelector("tr:nth-child(" + rowIndex + ") td"));
   	log.info(elements.size()+":");
   	List<String> result = new ArrayList<String>(elements.size());
   	for (WebElement e : elements) {
   		result.add(StringUtils.trim(e.getText()));
   	}
   	System.out.println(Arrays.asList(result));
   	return result;
   }
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:25,代码来源:SeleniumUtils.java

示例14: selectSemester

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
private void selectSemester() {
    final WebElement selectElement = driver.findElement(By.id("lbWeeks"));
    for (WebElement option : selectElement.findElements(By.tagName("option"))) {
        if (option.getText().toLowerCase().contains("semester")) {
            option.click();
            return;
        }
    }
}
 
开发者ID:gandreadis,项目名称:vu-timetable,代码行数:10,代码来源:Navigator.java

示例15: selectRadioButton

import org.openqa.selenium.WebElement; //导入方法依赖的package包/类
public static final void selectRadioButton(WebElement parent,int index){
   	SeleniumWaitUtils.waitForElement(By.cssSelector("input[type='radio']"));
   	List<WebElement> radioButton= parent.findElements(By.cssSelector("input[type='radio']"));
   	if(!radioButton.get(index).isSelected()){
   		radioButton.get(index).click();
   	}
}
 
开发者ID:21ca,项目名称:selenium-testng-template,代码行数:8,代码来源:SeleniumUtils.java


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