How do I verify that an element does not exist in Selenium 2

前端 未结 8 1094
误落风尘
误落风尘 2020-12-05 05:29

In Selenium 2 I want to ensure that an element on the page that the driver has loaded does not exist. I\'m including my naive implementation here.

    WebEle         


        
8条回答
  •  盖世英雄少女心
    2020-12-05 05:48

    public boolean exist(WebElement el){
       try {
          el.isDisplayed();
          return true;
       }catch (NoSuchElementException e){
          return false;
       }
    }
    
    if(exist(By.id("Locator details"))==false)
    

    or

    WebElement el= driver.findElementby(By.locator("locator details")
    public boolean exists(WebElement el)
     try{
      if (el!=null){
       if (el.isDisplayed()){
         return true;
    
        }
       }
     }catch (NoSuchElementException e){
       return false;
     }
    }
    

提交回复
热议问题