How do I click a javascript button with htmlunit?

前端 未结 3 1242
孤街浪徒
孤街浪徒 2020-12-19 22:46

I\'m working on an application that will automatically click a button on a webpage using htmlunit in Java. Only problem is that that button is a javascript button, so the st

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-19 23:08

    There's nothing special about clickable images. Something like this should work:

    button = page.getHtmlElementById( "1537385" ) ;
    page = button.click() ;
    

    HtmlUnit will then run the Javascript and return the updated page.

    If the id attribute of the 'a' tag isn't constant, you may need to use XPath to grab it.

提交回复
热议问题