HtmlUnit'te formun fireEvent
şeklinde gönderilebildiğini ve gönderileceğini biliyorum. Ama ya javascript'i devre dışı bırakmış ve bazı yerleşik işlevler kullanarak bir form göndermek istiyorsam?HtmlUnit, gönder düğmesine tıklamadan nasıl form gönderilir?
javadoc'u kontrol ettim ve bunu yapmanın herhangi bir yolunu bulamadım.
Ben HtmlUnit'in sayfasındaki javadoc ve öğretici okumak ve ben
getInputByName()
kullanmak ve bunu tıklayabilirsiniz Bil ki ... HtmlForm böyle bir işlevi olduğunu garip. BuT bazen, no'lu gönderim türü olmayan formlar veya isim düğmesi olmaksızın böyle bir düğme bile vardır.
Böyle bir durumda yardım isterim, bu yüzden fireEvent
kullanıyorum ama her zaman işe yaramıyor. the htmlunit doc
@Test
public void submittingForm() throws Exception {
final WebClient webClient = new WebClient();
// Get the first page
final HtmlPage page1 = webClient.getPage("http://some_url");
// Get the form that we are dealing with and within that form,
// find the submit button and the field that we want to change.
final HtmlForm form = page1.getFormByName("myform");
final HtmlSubmitInput button = form.getInputByName("submitbutton");
final HtmlTextInput textField = form.getInputByName("userid");
// Change the value of the text field
textField.setValueAttribute("root");
// Now submit the form by clicking the button and get back the second page.
final HtmlPage page2 = button.click();
webClient.closeAllWindows();
}
kullanıyorum tavsiye ederim bir 'HttpURLConnection' ve talimatlar özetlenen takip [burada] (http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests). Veya Apache'nin "HttpClient" sınıfını kullanın. – mrkhrts
JavaDoc'u tekrar kontrol edin :) Veya ayrıca Ransom Briggs'in yaptığı gibi Giriş -> Başlarken bölümü. Ben mrkhrts yaklaşımı için gitmek olmaz ... çok düşük seviye –