improve wait for page load 5.5.0-alpha-9
authorJochen Kemnade <jkemnade@apache.org>
Fri, 3 Nov 2017 10:53:09 +0000 (11:53 +0100)
committerJochen Kemnade <jkemnade@apache.org>
Fri, 3 Nov 2017 10:53:09 +0000 (11:53 +0100)
tapestry-test/src/main/java/org/apache/tapestry5/test/SeleniumTestCase.java

index 4a64591..a1fba91 100644 (file)
@@ -19,6 +19,7 @@ import com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor;
 
 import org.openqa.selenium.By;
 import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.NoSuchElementException;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
 import org.openqa.selenium.firefox.FirefoxDriver;
@@ -1377,15 +1378,20 @@ public abstract class SeleniumTestCase extends Assert implements Selenium
         // In a limited number of cases, a "page" is an container error page or raw HTML content
         // that does not include the body element and data-page-initialized element. In those cases,
         // there will never be page initialization in the Tapestry sense and we return immediately.
-
-        if (!isElementPresent("css=body[data-page-initialized]"))
+        try
         {
-            return;
-        }
-
+            WebElement body = webDriver.findElement(By.cssSelector("body"));
 
-        waitForCondition(ExpectedConditions.attributeToBe(By.cssSelector("body"), "data-page-initialized", "true"), 30);
+            if (body.getAttribute("data-page-initialized") == null)
+            {
+                return;
+            }
 
+            waitForCondition(ExpectedConditions.attributeToBe(body, "data-page-initialized", "true"), 30);
+        } catch (NoSuchElementException e)
+        {
+            // no body element found, there's nothing to wait for
+        }
     }
 
     @Override