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

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.
主站蜘蛛池模板: 遂平县| 安溪县| 沅陵县| 凌海市| 长治市| 鸡泽县| 稻城县| 琼海市| 漯河市| 琼中| 青岛市| 东丽区| 五指山市| 抚宁县| 新兴县| 白山市| 合山市| 巴林左旗| 元谋县| 五原县| 依兰县| 文昌市| 嘉黎县| 保定市| 武宁县| 双峰县| 溆浦县| 自贡市| 大理市| 惠来县| 胶南市| 望江县| 巴东县| 冷水江市| 博白县| 丰顺县| 洪湖市| 宝应县| 兴城市| 读书| 西青区|