isElementPresent in selenium 2.0

前端 未结 6 1396
太阳男子
太阳男子 2021-02-19 11:09

Hello all I am using webdriver so if I want to use selenium;s rc function isElementPresent I have to emulate selenium rc so I do something like this:

import org.         


        
6条回答
  •  囚心锁ツ
    2021-02-19 11:13

    In the Selenium 2 world, if you want to find if an element is present you would just wrap the find call in a try catch because if it isnt present it will throw an error.

    try{
      driver.findElement(By.xpath("//div"));
    }catch(ElementNotFound e){
      //its not been found
    }
    

提交回复
热议问题