PageObject.find(By... selectors) and NoSuchElementException

19 views
Skip to first unread message

martin...@gmail.com

unread,
Jan 2, 2017, 6:47:28 AM1/2/17
to Serenity BDD Users Group
 See the following mehtods:

 public <T extends net.serenitybdd.core.pages.WebElementFacade> T find(List<By> selectors) {
        T element
= null;
       
for (By selector : selectors) {
           
if (element == null) {
                element
= element(selector);
           
} else {
                element
= element.find(selector);
           
}
       
}
       
return element;
   
}
 
public <T extends net.serenitybdd.core.pages.WebElementFacade> T element(By bySelector) {
       
return net.serenitybdd.core.pages.WebElementFacadeImpl.wrapWebElement(driver,
                bySelector
,
                getImplicitWaitTimeout
().in(MILLISECONDS),
                getWaitForTimeout
().in(MILLISECONDS),
                bySelector
.toString());
   
}

Looking at the method find(List<By> selelectors) one can see that in the if branch of the if clause element(selector) is being called. This result in an instance of WebElementFacadeImpl without checking if the element is present on the page (not visible, just present) or not. Though, in the else branch element.find(selector) is called, which causes a NoSuchElementException to be thrown if the element is not present.

In my opinion this behaviour is a bit inconsistent. In older version there has always beent trigged a NoSuchElementException whenever the element could not be located on page.
Reply all
Reply to author
Forward
0 new messages