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

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.
主站蜘蛛池模板: 保德县| 武鸣县| 囊谦县| 延安市| 新民市| 洪雅县| 柏乡县| 方城县| 高州市| 长顺县| 香河县| 长海县| 神池县| 玉田县| 红桥区| 巴林右旗| 郁南县| 平舆县| 慈利县| 新干县| 平山县| 隆林| 鲜城| 宝鸡市| 扶绥县| 驻马店市| 基隆市| 绥阳县| 十堰市| 天气| 黄陵县| 克东县| 库车县| 通山县| 文化| 丰城市| 永善县| 巴林左旗| 阳春市| 伽师县| 家居|