- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 185字
- 2021-08-13 16:08:05
The findElement method
In UI automation, locating an element is the first step before executing any user actions on it. WebDriver's findElement() method is a convenient way to locate an element on the web page. According to WebDriver's Javadoc (http://selenium.googlecode.com/git/docs/api/java/index.html), the method declaration is as follows:
WebElement findElement(By by)
So, the input parameter for the findElement() method is the By instance. The By instance is a WebElement-locating mechanism. There are eight different ways to locate a WebElement on a web page. We will see each of these eight methods later in the chapter.
The return type of the findElement() method is the WebElement instance that represents the actual HTML element or component of the web page. The method returns the first WebElement that the driver comes across that satisfies the locating-mechanism condition. This WebElement instance will act as a handle to that component from then on. Appropriate actions can be taken on that component by the test-script developer using this returned WebElement instance.
If WebDriver doesn't find the element, it throws a runtime exception named NoSuchElementException, which the invoking class or method should handle.
- Web安全防護指南:基礎篇
- 網絡協(xié)議工程
- 網管員典藏書架:網絡管理與運維實戰(zhàn)寶典
- 物聯(lián)網網絡安全及應用
- 局域網組建、管理與維護項目教程(Windows Server 2003)
- 通信簡史:從信鴿到6G+
- 射頻通信系統(tǒng)
- 工業(yè)互聯(lián)網創(chuàng)新實踐
- 轉化:提升網站流量和轉化率的技巧
- 物聯(lián)網M2M開發(fā)技術:基于無線CPU-Q26XX
- NB-IoT原理和優(yōu)化
- INSTANT Social Media Marketing with HootSuite
- 趣話通信:6G的前世、今生和未來
- 物聯(lián)網導論
- Hands-On Cloud:Native Microservices with Jakarta EE