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

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. 

主站蜘蛛池模板: 宜阳县| 上高县| 防城港市| 彰武县| 什邡市| 东城区| 稷山县| 张北县| 沙河市| 井陉县| 托克托县| 内丘县| 广南县| 色达县| 柳江县| 万宁市| 山东省| 唐海县| 许昌县| 灌云县| 读书| 习水县| 南昌县| 白河县| 辽中县| 渝北区| 凌海市| 固始县| 雅安市| 健康| 平阴县| 大渡口区| 纳雍县| 弥渡县| 武功县| 车致| 东阳市| 凤冈县| 仪陇县| 冕宁县| 万盛区|