- Selenium WebDriver Quick Start Guide
- Pinakin Chaubal
- 140字
- 2021-06-24 18:26:30
Finding elements within the container element
On the http://www.freecrm.com login page, the structure is such that the username, password, and the login button are contained inside the form with id=xyz. In such a situation, the child elements can be accessed using findElements on the container or parent element.
The following code displays the number of input elements in the form:
public class DynamicText1 {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\SeleniumWD\\src\\main\\resources\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.freecrm.com");
String dynamicXpath = "http://*[@id='loginForm']";
List<WebElement> elem =
driver.findElements(By.xpath(dynamicXpath));
List<WebElement> elem1 =
elem.get(0).findElements(By.tagName("input"));
System.out.println("no of elements: " + elem1.size());
}
}
The output displayed in console is shown below
no of elements: 3
This is a very simple program which has hardcoded values. To remove hardcoding from a program, we require a framework, which we will discuss in forthcoming chapters.
推薦閱讀
- Social Media Mining with R
- Linux系統(tǒng)文件安全實戰(zhàn)全攻略
- 零起點學(xué)Linux系統(tǒng)管理
- UNIX操作系統(tǒng)設(shè)計
- 構(gòu)建可擴展分布式系統(tǒng):方法與實踐
- Java EE 8 Design Patterns and Best Practices
- 嵌入式Linux應(yīng)用開發(fā)菜鳥進階
- 直播系統(tǒng)開發(fā):基于Nginx與Nginx-rtmp-module
- Linux內(nèi)核觀測技術(shù)BPF
- INSTANT Migration from Windows Server 2008 and 2008 R2 to 2012 How-to
- Linux服務(wù)器配置與管理
- RHCSARHCE 紅帽Linux認證學(xué)習(xí)指南(第7版)EX200 & EX300
- Windows 8實戰(zhàn)從入門到精通(超值版)
- Linux應(yīng)用大全 基礎(chǔ)與管理
- Raspberry Pi入門指南