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

SearchContext interface 

SearchContext is the interface that has been designed to find elements in the DOM using a locator mechanism. SearchContext has two public methods:

  • findElementThis identifies all matching elements based on a locator mechanism but always returns the first matching web element.
  • findElements: This returns a list of WebElements that match the locator.

When Selenium returns a WebElement, it does not return an object of the WebElement, since the WebElement is an interface. Rather, it returns an object of RemoteWebElement, which is the implementation class of the WebElement interface.

What if the locator mechanism does not return any elements? In this case, findElement will always throw a NoSuchElementException. The findElements method, on the other hand, will not throw a No SuchElementException. It returns an empty list. 

Always use findElements when unsure about the existence of a WebElement based on some locator mechanism. This is the best practice to avoid NoSuchElementException at runtime. It is very likely you'll get this exception while using the  By.tagName static method, which we will see later.
主站蜘蛛池模板: 长岛县| 墨脱县| 宁武县| 托克逊县| 民勤县| 天等县| 邹城市| 同江市| 香港| 泽普县| 阳东县| 永川市| 肃宁县| 阳春市| 定州市| 松溪县| 塔城市| 金秀| 海阳市| 阿图什市| 北宁市| 望奎县| 兴国县| 榕江县| 昔阳县| 枣庄市| 石首市| 青田县| 三穗县| 丹棱县| 江源县| 正定县| 土默特左旗| 香格里拉县| 新竹县| 桃园市| 湘潭县| 大同市| 龙川县| 晋城| 内乡县|