I have to submit a form on the page. I navigate, inject my scripts, then fill out a form, and hit submit.
However, the form is a standard post, not ajax, and so everything will be reloaded by the browser.
What would be the best way to find out when the new page has actually reloaded?
The loadAdapter functionality will not be available then since I didn't navigate to the url using loadURL() but the page was reloaded within the browser itself.
I could manually sleep for a certain amount of time, however i'd like to know if there is a better solution.
You can use the LoadAdapter for standard POST requests. Please take a look at the sample code below:
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.FrameLoadEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class LoadListenerSample {
public static void main(String[] args) {
final Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
browser.addLoadListener(new LoadAdapter() {
@Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
System.out.println("LoadListenerSample.onFinishLoadingFrame");
}
@Override
public void onDocumentLoadedInFrame(FrameLoadEvent event) {
System.out.println("LoadListenerSample.onDocumentLoadedInFrame");
}
});
browser.loadURL("https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit");
}
}