MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

Executing driver.getPageSource() results in IllegalStateException #253

Closed vrosu closed 7 years ago

vrosu commented 7 years ago

Hi Dan,

I have an issue which surfaced only after installing more recent version of Java 8 (I don't know which version triggers this unfortunately). Whenever I call driver.getPageSource() I get an java.lang.IllegalStateException: Not on FX application thread; currentThread = RMI TCP Connection(2)-192.168.0.2 Where the IP address is my local laptop - with or without firewall activated.

It just stopped working out of a sudden...got any hints that I might follow?

The code I use is the following: Settings sett = Settings.builder().requestHeaders(new RequestHeaders(map)).screen(dim).blockAds(false) .quickRender(false).ajaxWait(10000).build();

    JBrowserDriver driver = new JBrowserDriver(sett);
    driver.get(server);
    String str_PageSource = driver.getPageSource();

I'm using 0.10.1 version

hollingsworthd commented 7 years ago

I'm curious what happens if you try driver.findElementByTagName("html").getAttribute("outerHTML"); which is largely what getPageSource() does.

Sometimes the html tag and its outerHTML aren't present in the DOM for various reasons so there's a fallback in getPageSource that relies on built in Java APIs to get page source. I moved that fallback to the event thread which might be the cause of the exception you have.

However, if it's relying on the fallback every time, that's a bug in itself because it means driver.findElementByTagName("html").getAttribute("outerHTML"); never works--it should work in the vast majority of cases.

See v0.17.5. Thanks!

hollingsworthd commented 7 years ago

I'm using 0.10.1 version

Can you also let me know if this works in v0.17.3?

v0.17.5 has the changes to the fallback mentioned above along with some unrelated changes.

vrosu commented 7 years ago

Tried with 0.17.3 and it simply worked...I have no idea what was the reason, but we can close this:)