0

I'm testing a website using ui4j. When I execute

page.executeScript("window.scrollTo(0,document.body.scrollHeight)");

to scroll to the end of the page I get the following NullPointerException:

Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
    at com.sun.javafx.webkit.theme.ScrollBarThemeImpl.getThumb(ScrollBarThemeImpl.java:400)
    at com.sun.javafx.webkit.theme.ScrollBarThemeImpl.thumbPosition(ScrollBarThemeImpl.java:284)
    at com.sun.javafx.webkit.theme.ScrollBarThemeImpl.getThumbPosition(ScrollBarThemeImpl.java:380)
    at com.sun.webkit.WebPage.twkExecuteScript(Native Method)
    at com.sun.webkit.WebPage.executeScript(WebPage.java:1427)
    at javafx.scene.web.WebEngine.executeScript(WebEngine.java:948)
    at com.ui4j.webkit.spi.WebKitJavaScriptEngine.executeScript(WebKitJavaScriptEngine.java:26)
    at com.ui4j.webkit.browser.WebKitPage.executeScript(WebKitPage.java:231)
    at com.ui4j.webkit.browser.WebKitPage$ByteBuddy$sjifLXwz.executeScript$accessor$6vHNXtoG(Unknown Source)
    at com.ui4j.webkit.browser.WebKitPage$ByteBuddy$sjifLXwz$auxiliary$0UdQY8PH.call(Unknown Source)
    at com.ui4j.webkit.proxy.WebKitProxy$CallableExecutor.run(WebKitProxy.java:46)
    at com.sun.javafx.application.PlatformImpl.lambda$null$170(PlatformImpl.java:295)
    at com.sun.javafx.application.PlatformImpl$$Lambda$51/1744951114.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$171(PlatformImpl.java:294)
    at com.sun.javafx.application.PlatformImpl$$Lambda$50/929850074.run(Unknown Source)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95) 

I tried it with ui4j 2.0 and 1.2.0 on a mac. JDK version 1.8.0_45 .

Is there some configuration on ui4j missing to be able to execute 'window.scrollTo'?

I load the webpage the following way:

BrowserEngine engine = BrowserFactory.getWebKit();
Page page = engine.navigate( url );

Am I missing something or is there a workaround for 'window.scrollTo' under ui4j to avoid the NullPointerException?

Vincent
  • 470
  • 6
  • 13
  • possible duplicate of [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – almightyGOSU Jul 08 '15 at 12:07
  • 1
    Not at all. I did not ask what a NullPointerException is! My question is about the specific case described above (Calling 'window.scrollTo' in ui4j causing a NPE in 'ScrollBarThemeImpl.getThumb'). – Vincent Jul 08 '15 at 12:37

1 Answers1

1

Before the page.executeScript() call page.show()

import static com.ui4j.api.browser.BrowserFactory.getWebKit;

import com.ui4j.api.browser.Page;

public class Sample {

    public static void main(String[] args) {
        Page page = getWebKit().navigate("http://stackoverflow.com");
        page.show();
        page.executeScript("window.scrollTo(0,document.body.scrollHeight)");
    }
}
  • Thank you! page.show() works if I run the unit test in eclipse. When I build the project with maven and the test case is executed I still get the same NullPointerException described above – Vincent Jul 08 '15 at 12:59
  • sorry that was just a dependency build problem. page.show() works both in eclipse and in maven! – Vincent Jul 08 '15 at 13:05