- 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.
推薦閱讀
- 全屋互聯:智能家居系統開發指南
- Designing Purpose:Built Drones for Ardupilot Pixhawk 2.1
- Kali Linux滲透測試全流程詳解
- 嵌入式操作系統(Linux篇)(微課版)
- Linux自動化運維:Shell與Ansible(微課版)
- Kali Linux高級滲透測試
- 跟老男孩學Linux運維:Shell編程實戰
- 新編電腦辦公(Windows 10+ Office 2013版)從入門到精通
- Linux軟件管理平臺設計與實現
- Windows Server 2008組網技術與實訓(第3版)
- Raspberry Pi入門指南
- Linux內核分析及應用
- Mastering Eclipse Plug-in Development
- Getting Started with Raspberry Pi Zero
- Linux網絡操作系統項目教程(RHEL 6.4/CentOS 6.4)(第2版)