Friday, September 4, 2009

Selenium - Element not found

Why Element not found error Occurs ??

Why Element not found error occurs ??
This is most simple but most occurred error. There can be only one of two things why this error appears
  1. Locator(ID, Name, XPath, DOM or CSS) you have given is wrong
  2. Element is not visible
Now there can be two reason why element is not visible
  1. Element is not present on that page, may be wrong page has opened or element has been removed. Or
  2. Element is not visible element has not been loaded yet (Page hasn't loaded fully)

Solution is also easy. First check manually if element is present on the page or not. If it is present try to wait until that element appears. If your element is not being loaded as a ajax call you can simple use following function, which will wait until page loads.
you can increase the time if page is taking more time to load.

But if your element is being loaded as a part of AJAX call, you can use the following function to wait until that element appears or timeout occurs.

The function will return true if element will be found on page within giving time else will return false.

  * @author Gaurang
  * @param locator 
  * @param timeout (minutes)
  * @throws InterruptedException
  * @return returns true if element found in given time else false
  *  wait until specified element appears or timeout occurs
 public boolean waitForElementPresent(String xpath, int timeout) throws InterruptedException{
  int count = 0;
  while(selenium.isElementPresent(xpath) != true){
   Thread.sleep(10*1000); //Wait 10 seconds
   if(count++ > timeout*6 ) break;
   return true;
   return false;


Senior Quality Control And Testing Engineer said...

how can i put the selenim.setspeed before the execte



Talja said...

thx, for help:)was useful for me

Talja said...

was useful for me, thx for help:)

Selenium User said...

I tried using selenium.waitForPageToLoad("60000");
But still I get element not found.

any ideas?


Post a Comment