官术网_书友最值得收藏!

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. 

主站蜘蛛池模板: 深水埗区| 夹江县| 泰兴市| 安国市| 山阴县| 饶阳县| 陇南市| 渑池县| 肥西县| 宁武县| 吐鲁番市| 聊城市| 乌兰察布市| 漳浦县| 大埔区| 龙南县| 景东| 平舆县| 灵寿县| 三明市| 丘北县| 湘西| 武安市| 漳州市| 田东县| 馆陶县| 辉县市| 德钦县| 正镶白旗| 高邮市| 台江县| 杭锦后旗| 西峡县| 上杭县| 永福县| 上蔡县| 汝南县| 察隅县| 子洲县| 察雅县| 全州县|