0

I'am using Selenium with Standalone Server (V2.48.2) with NetBeans and using Firefox (V44.0).

I have tried different ways to get this fixed, but its an error that appears to be random in different parts of my code every once in a while; "Timed out after 10 seconds waiting for presence of element located" Sometimes it works all fine and processes everything.

I currently use wait.until(ExpectedConditions.presenceOfElementLocated(by)) method to wait for page to load, but it is still giving me this issue. This occurs in a filter of 4 dropdown lists, one enables another:

<form name="ymme-form">
          <select name="year" id="year">
                  <option>Year</option></select>
          <select name="make" disabled="">
                  <option>Make</option></select>
          <select name="model" disabled="">
                  <option>Model</option></select>
          <select name="engine" disabled="">
                  <option>Engine</option></select>
     <button class="button" disabled="">
                 <span>ADD VEHICLE</span></button></form>

The next code is highly modified from what i had in the beginning (note the Try Catch code repeated) because i tried to force this in many ways, but any advice on the code is highly appreciated:

for(int attemptMake = 0; attemptMake<attemptsForFilters;attemptMake++){
                           try{
                            wait.until(ExpectedConditions.presenceOfElementLocated(By.name("make")));
                           boolean makeDisplay = driver.findElement(By.name("make")).isDisplayed();
                           boolean makeFilters = driver.findElement(By.name("make")).isEnabled();
                             if(makeDisplay){
                                   if(makeFilters){
                                    Select makeSelect = new Select(driver.findElement(By.name("make")));
                                      List<WebElement> listMake = makeSelect.getOptions();
                                           for(int m = 1;m<listMake.size();m++){
                                               if(listMake.get(m).getText().toLowerCase().equals(lineProcess.make.toLowerCase())){
                                                          makeProcess = listMake.get(m).getText();
                                                          makeSelect.selectByIndex(m);
                                                          break;
                                               }
                                           }
                                      }
                                                 } else if (!makeFilters){
                                                    System.out.println("Not Make Option detected for: " + lineProcess.model + " - attempt: " + attemptMake);
                                                }
                           } catch(Exception e){
                                wait.until(ExpectedConditions.presenceOfElementLocated(By.name("make")));
                           boolean makeDisplay = driver.findElement(By.name("make")).isDisplayed();
                           boolean makeFilters = driver.findElement(By.name("make")).isEnabled();
                             if(makeDisplay){
                                   if(makeFilters){
                                    Select makeSelect = new Select(driver.findElement(By.name("make")));
                                      List<WebElement> listMake = makeSelect.getOptions();
                                           for(int m = 1;m<listMake.size();m++){
                                               if(listMake.get(m).getText().toLowerCase().equals(lineProcess.make.toLowerCase())){
                                                          makeProcess = listMake.get(m).getText();
                                                          makeSelect.selectByIndex(m);
                                                          break;
                                               }
                                           }
                                      }
                                                 } else if (!makeFilters){
                                                    System.out.println("Not Make Option detected for: " + lineProcess.model + " - attempt: " + attemptMake);
                                                }
                           }
                           }

Thanks in advance for any help.

Edit:

Also I'm constantly getting this error

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM

Even if I have waited for the Element before or validated it:

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[@id='ymmeOverlayMainContent']/div[@class='ymmeWidget']/form/button[@class='button']")));
                            WebElement submitAddvehicle = driver.findElement(By.xpath("//div[@id='ymmeOverlayMainContent']/div[@class='ymmeWidget']/form/button[@class='button']"));
                            if(submitAddvehicle.isEnabled()){
                                driver.findElement(By.xpath("//div[@id='ymmeOverlayMainContent']/div[@class='ymmeWidget']/form")).click();
                                submitAddvehicle.click();
                                executor.executeScript("arguments[0].click();", submitAddvehicle); //<---- Here is the error
                                executor.executeScript("arguments[0].click();", submitAddvehicle);
                                }
  • if i get this error in katalon recoreder how can i resolve this one – user42100 Oct 24 at 12:13
0

There are 2 possibilities what is going on:

  1. some call of selenium functions will time out (click, type, etc.) after some time because the object is not there at all.
  2. even if you will enable the wait.until, this has its own timeout (could be 30 sec.) in selenium.

Case 1) is solved by enabling waits before some click or other action should happen.

To solve case 2) for extremely slow applications you have to check presence of some object in the cycle and continue afterwards.

Try to use this solution: https://stackoverflow.com/questions/20903231/selenium-wait-until-element-is-present to get you test waiting for your app.

0

use implicit wait to handle all kind of sync issues.

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

user this at the time of declaring the web driver object; like:

WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://somedomain/url_that_delays_loading");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));
0

By doing some heavy research, I was able to find the solution by using:

wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.finder));

The key was to find all the elements present in the part where i was going to validate if it was available. This solved the Time out's error:

As for the Element is no longer attached to the DOM, and the validations, instead of using the .IsDisplayed or .IsEnabled which DON'T returns "false" but an exception, i was able to validate this using

findElements(By.finder).size()>0

This returns false or true if the element size is displaying or not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.