oneCoderToRuleThemAll
oneCoderToRuleThemAll

Reputation: 865

HtmlUnit submitting a form?

I am trying to submit the form on the website: http://pfam.xfam.org/search using java and HtmlUnit but I can't get it to work. I think the problem is that the "Submit" button is not really a button but some form of other input. I am not too familiar with all the Html elements and I just got started with HtmlUnit. Any help would be highly appreciated. Below is my code so far, which enter a sequence to the form:

import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.html.*;

public class ProteinSearch {


    static String protein = "MAGAASPCANGCGPSAPSDAEVVHLCRSLEVGTVMTLFYSKKSQRPERKTFQVKLETRQITWSRGADKIEGAIDIREIKEIRPGKTSRDFDRYQEDPAFRPDQSHCFVILYGMEFRLKTLSLQATSEDEVNMWIRGLTWLMEDTLQAATPLQIERWLRKQFYSVDRNREDRISAKDLKNMLSQVNYRVPNMRFLRERLTDLEQRTSDITYGQFAQLYRSLMYSAQKTMDLPFLEASALRAGERPELCRVSLPEFQQFLLEYQGELWAVDRLQVQEFMLSFLRDPLREIEEPYFFLDEFVT";

    public static void main(String[] args) {

        WebClient client = new WebClient();
        try
        {
            HtmlPage currentPage = (HtmlPage)client.getPage("http://pfam.xfam.org/search");
            HtmlForm form = (HtmlForm) currentPage.getElementById("proteinSeqSearchForm");
            HtmlTextArea searchBox = form.getTextAreaByName("seq");

            searchBox.setTextContent(protein);

            //currentPage = form.getAcceptAttribute();

            System.out.println(form.getId());
        }
        catch(Exception ex)
        {
            System.out.println("Some form of error happened !");
        }


    }


}

Upvotes: 1

Views: 4590

Answers (1)

Tasawer Nawaz
Tasawer Nawaz

Reputation: 925

you may try like this

HTMLButtonElement button = (HTMLButtonElement) page
        .getByXPath("//input[@class='submit']").get(0);
HtmlPage result_page = button.click();

Upvotes: 4

Related Questions