2017-08-24 41 views
0

我必須在頁面上提交一個表單。我瀏覽,注入我的腳本,然後填寫表單,然後點擊提交。JXBrowser,等待window.location =另一個網址

然而,形式是標準後不是阿賈克斯等等應有盡有會被瀏覽器重新加載

什麼是最好的方式來找出新的頁面實際上重新加載?

loadAdapter功能將不可用,則因爲我沒有導航使用使用loadURL()的網址,但該頁面被瀏覽器本身內重新加載。

我可以手動睡一段時間,但我想知道是否有更好的解決方案。

回答

1

您可以使用LoadAdapter進行標準的POST請求。請看下面的示例代碼:

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"); 
} 
}