- 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.
推薦閱讀
- Citrix XenApp Performance Essentials
- Windows Server 2012 Hyper-V:Deploying the Hyper-V Enterprise Server Virtualization Platform
- Linux從零開始學(xué)(視頻教學(xué)版)
- SharePoint 2013 WCM Advanced Cookbook
- Windows Phone應(yīng)用程序開發(fā)
- Windows Server 2019 Administration Fundamentals
- 巧學(xué)活用Windows 7
- 從實踐中學(xué)習(xí)Kali Linux無線網(wǎng)絡(luò)滲透測試
- 一學(xué)就會:Windows Vista應(yīng)用完全自學(xué)手冊
- RHCSARHCE 紅帽Linux認(rèn)證學(xué)習(xí)指南(第7版)EX200 & EX300
- Windows Server 2008組網(wǎng)技術(shù)與實訓(xùn)(第3版)
- Multi-Cloud for Architects
- Linux集群之美
- 計算機應(yīng)用基礎(chǔ)(Windows 7+Office 2010)
- 微軟360度