4

For my UI tests I'm using page factory model with webdriver (version 2.45.0). For a driver I use phantomjs (version 1.9.8). In a separate class I have a method similar to this:

public WebElement waitTillNotVisible(By locator, WebDriver driver){
    return new WebDriverWait(driver, 10).
            until(ExpectedConditions.invisibilityOfElementLocated(locator));
}

Every time the waitTillNotVisible is called, I'm getting error in the console log,

[ERROR - 2015-04-08T11:30:18.149Z] WebElementLocator - _handleLocateCommand - Element(s) NOT Found: GAVE UP. Search Stop Time: 1428492618108

but the tests continue and pass. What is the reason for such behavior, and how to avoid it? This looks to me like a bug of phantomjs, as no such message appears when testing with FirefoxDriver.

casper
  • 1,391
  • 2
  • 16
  • 29

1 Answers1

3

In order to use invisibilityOfElementLocated the element needs to present in DOM If I understand it correctly. Looks like the error has been thrown because the element does not exist/ the element was not found using given selector.

Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Why it's not an issue with firefox driver? – casper Apr 08 '15 at 12:59
  • Well, I am not sure. But, we have to keep that in mind PhantomJs and Firefox do not work in similar ways. Can you see if that element at least exists with possibly `presenceOfElementLocated` in PhantomJs first – Saifur Apr 08 '15 at 13:02
  • well, the element I am testing should disappear from DOM. Perhaps there's a better expected condition for that. stalenessOf does not work for me, as it throws element not found exception. – casper Apr 08 '15 at 13:05
  • Yes. What I am trying to say is *Invisible* and *does not exist* (disappear ) are not same. invisible probably mean element exist in the dom but not visible means hidden and that's probably your problem – Saifur Apr 08 '15 at 13:08
  • how do I wait till element is not present in dom (other than findElemens in a loop)? – casper Apr 08 '15 at 13:30
  • Probably find a size of the elements using `int size = driver.findElements("your selector").size();` and see if the size is more than *0* if so element exist else not – Saifur Apr 08 '15 at 13:33
  • well, that's exactly what I am trying to avoid, by using expected conditions. To me it sounds like a simple thing and probably widely used, so I don't get it why there's no standard method for this scenario. – casper Apr 08 '15 at 13:38
  • @casper I do not know why would you want to wait 10s to fail the test but avoid `count` which does not cost you anything. As I said, invisiblitity(need to look into source code)would,probably, work when element becomes invisible from visible and would not work if element does not exist at all. Why would not you try something like `public WebElement waitTillNotVisible(By locator, WebDriver driver){ int size = driver.findElements("your selector").size(); if(size>0){ return new WebDriverWait(driver, 10). until(ExpectedConditions.invisibilityOfElementLocated(locator)); } }` – Saifur Apr 08 '15 at 13:43
  • findElements uses implicit wait timeout which I set up once when I configure driver instance. So in case it does not find the element , it will wait for 10, 20 or whatever seconds, that are defined in implicitly wait. In other words - findElements can be very slow – casper Apr 08 '15 at 14:04
  • @casper if that's the case then you are killing 20s even **without using `findElements`**. See [this](http://stackoverflow.com/questions/29474296/clarification-on-the-cause-of-mixing-implicit-and-explicit-waits-in-selenium-doc) to know how. All I am saying is **add an extra check to see if even the element exist before even start looking for the element's visibility**. We are struggling with two completely different things here – Saifur Apr 08 '15 at 14:13