-1

I am currently trying to automate web page contains few js and jQuery implementations using selenium WebDriver. I have noticed few posts says about implementing the code to wait for page load completely.

ExpectedCondition<Boolean> jQueryLoad = new ExpectedCondition<Boolean>() {
        @Override
        public Boolean apply(WebDriver driver) {
            try {
                return ((Long) executeJavaScript("return jQuery.active") == 0);
            } catch (Exception e) {
                return true;
            }
        }
    };

But I am unable to solve'undefined type error' thrown by the use of 'executeJavaScript'. Can someone guide me which library I am missing? or How to work with this code.

Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
ajesh
  • 91
  • 12
  • Appreciate those who devote with **comments**. I have put effort to understand unclear or unwanted posts/code posted in StackOverflow when I confront with. – ajesh Nov 24 '16 at 13:26

1 Answers1

0

There is no such method executeJavaScript, there is one method executeScript which you can use to execute your javascript but for that you have to cast your webdriver instance into JavascriptExecutor. Below is the code for your reference:-

Replace your return statement with following:-

((long)((JavascriptExecutor)driver).executeScript("return jQuery.active") == 0);
Paras
  • 3,197
  • 2
  • 20
  • 30
  • Thanks for pointing this. But please have a look at this [link] (http://stackoverflow.com/questions/10720325/selenium-webdriver-wait-for-complex-page-with-javascriptjs-to-load). I tried by casting Driver instance to JavaScriptExecutor. 'return ((long)js.executeScript("return jQuery.active") == 0);'. – ajesh Nov 24 '16 at 12:12
  • which selenium version jar are you using? – Paras Nov 24 '16 at 12:23
  • I am using 'selenium-server-standalone-3.0.1' with JDK 1.8. – ajesh Nov 24 '16 at 12:29
  • check if you have guava.jar in your build path? – Paras Nov 24 '16 at 12:39
  • I have added 'guava.jar' in my classpath before posted in StackOverflow. But that didn't resolve my problem. – ajesh Nov 24 '16 at 13:04