Question

public void actionVote() {
    HtmlForm form = this.page.getForms().get(0);
    HtmlInput button = form.getInputByValue("vote");
    try {
        button.click();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

When i do println with button.asText(), it gives me the correct value of the submit button, but when I do button.click, nothing happens, like it doesn't submit the form.

I can't get the button using HtmlButton because the submit button doesn't have any id or name. I also can't make it HtmlButton from HtmlInput.

Why doesn't this submit? Wrong element?

Was it helpful?

Solution

Try this - getInputByName or getButtonByName

HtmlForm form = this.page.getForms().get(0);
HtmlInput button = form.getInputByName("vote");

Or you can also create a fake button:

HtmlElement fakeButton = page.createElement("button");
button.setAttribute("type", "submit");

// add the button to the form
form.appendChild(fakeButton );
fakeButton.click();

OTHER TIPS

Can you try below code:

HtmlForm form = page.getForms().get(0);

HtmlElement input = form.getElementsByAttribute("input", "name", "vote").get(0);

page =  input.click();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top