isElementPresent in selenium 2.0

前端 未结 6 1423
太阳男子
太阳男子 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:26

    Sometimes the element you are trying to find is loading, s0 will throw an exception using

      findElement(By.xpath(xpathLocator))  

    Therefore we would need do what Dejan Veternik has recommended, it will help wait until the ELEMENT has been loaded in the webpage, I am passing Selenium and extracting webdriver, this is helpful incase you are using WebDriverBackedSelenium just like me ...

     private boolean isElementPresent(WebDriverBackedSelenium driver, String id) {
            try {
                driver.getWrappedDriver().findElement(By.id(id));
                return true;
    
            } catch (Exception e) {
                return false;
            }
        }
    
     

提交回复
热议问题