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

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.
主站蜘蛛池模板: 犍为县| 旅游| 饶河县| 洛浦县| 任丘市| 保定市| 海南省| 红河县| 颍上县| 泰顺县| 陵川县| 惠州市| 缙云县| 深水埗区| 房产| 瑞丽市| 兰考县| 台州市| 彭水| 南郑县| 淄博市| 嵩明县| 东辽县| 盐津县| 临泉县| 县级市| 当涂县| 峡江县| 儋州市| 永胜县| 永顺县| 兴义市| 汝阳县| 菏泽市| 揭西县| 社会| 康定县| 萨迦县| 墨脱县| 耒阳市| 铜山县|