1

We have problems when checked if a element exist in the page

Example

return driver.wait(function() {
                driver.findElement(By.css(".class")).then(function(element){
                                      if(element){
                                        return true;
                                      }
                                    },function(error){
                                        if(error){
                                          return false;
                                        }
                                  });
                }, 2000);

In this function the 2000 seconds timeout never is executed and we obtains timeout from webdriver

Thank you very much :)

tuto
  • 11
  • 3

1 Answers1

2

Are you trying to check that an element exists, or wait until the element exists? These are two different things.

Check Element Exists:

driver.isElementPresent(webdriver.By.css('.class')).then(function(present) {
   console.log(present);
});

Wait For An Element To Exist

driver.wait(webdriver.until.elementLocated(webdriver.By.css('.class')), 2000);
Alister Scott
  • 3,675
  • 24
  • 41
  • 3
    i couldn't find an `isElementPresent` method in the selenium docs. is this answer still valid? – RZKY Feb 28 '17 at 09:39