htmlUnit - clicking a button

I have spent a lot of time trying to figure it out, testing etc but I can't get it to work. Basically, I want it to click a button (not js) with text "Enter a". No text like that is found other where.

Code for the button:

<div class="votebox">
   <span class="votehead"> </span>
   <br><br>
   <a href="http://www.link-where-it-redirects.com" class="cssbuttongo">Enter a</a><br><br><br>
   <span class="votehead"> </span>
  </div>

How can I make it so it will click that button?

Upvotes: 2

Views: 2296

Answers (1)

Mosty Mostacho
Mosty Mostacho

Reputation: 43434

The reason why you can't click a button is that there is no button but rather an anchor. There are many ways to get that anchor but probably the easier one would be using getAnchorByText(String) this way:

WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://yourpage.com");
HtmlAnchor anchor = page.getAnchorByText("Enter a");
page = anchor.click();

If I didn't commit any syntactical error while typing that then that would do the trick.

Upvotes: 1

Related Questions