- 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.
推薦閱讀
- 30天自制操作系統(tǒng)
- Linux運(yùn)維實(shí)戰(zhàn):CentOS7.6操作系統(tǒng)從入門(mén)到精通
- Mobile-first Bootstrap
- Ubuntu Linux操作系統(tǒng)
- Implementing Azure DevOps Solutions
- Instant Optimizing Embedded Systems using Busybox
- 從實(shí)踐中學(xué)習(xí)Kali Linux無(wú)線網(wǎng)絡(luò)滲透測(cè)試
- Learning Continuous Integration with Jenkins(Second Edition)
- Zabbix監(jiān)控系統(tǒng)之深度解析和實(shí)踐
- Learn Quantum Computing with Python and IBM Quantum Experience
- UNIX傳奇:歷史與回憶
- Microsoft DirectAccess Best Practices and Troubleshooting
- Windows 10從入門(mén)到精通
- 龍芯電腦使用解析(統(tǒng)信 UOS版)
- 深入理解分布式事務(wù):原理與實(shí)戰(zhàn)