Best way to check that element is not present using Selenium WebDriver with java

后端 未结 9 1988
半阙折子戏
半阙折子戏 2020-12-24 02:33

Im trying the code below but it seems it does not work... Can someone show me the best way to do this?

public void verifyThatCommentDeleted(final String text         


        
9条回答
  •  星月不相逢
    2020-12-24 02:49

    Use findElements instead of findElement.

    findElements will return an empty list if no matching elements are found instead of an exception. Also, we can make sure that the element is present or not.

    Ex: List elements = driver.findElements(By.yourlocatorstrategy);

    if(elements.size()>0){
        do this..
     } else {
        do that..
     }
    

提交回复
热议问题