patrick
patrick

Reputation: 21

Click a button on a webpage

I'm using the Process p=Runtime.getRuntime().exec to open a webpage. What event handler would I use to click a button on the open webpage using Java?

Upvotes: 0

Views: 264

Answers (2)

Richie
Richie

Reputation: 9266

Adding on to the answer and comments from radai

a. "have program that will do this already but it will not work with in my Work domain because of bluecoat security because of a lack of a browser" - This is not because of the lack of browser. It is because your java process does not have the proxy credentials to hit the page. The http calls going from the tool, is directed through your proxy. You can try setting the environment with required properties.

If you are running the tool from command line - You can try something like this

JAVA_FLAGS=-Dhttp.proxyHost=10.0.0.100 -Dhttp.proxyPort=8800
java ${JAVA_FLAGS} <java_class_to_run>

b. If you are planning to re-create the tool - jsoup is another great option

Upvotes: 0

radai
radai

Reputation: 24192

None, really. You don't have any such fine-grained control over a process you initiate; all you get are the input, output, and error streams from the process.

If you want to interact with webpages from Java (but not display them on the screen), you can have a look at HtmlUnit.

You can configure HtmlUnit to impersonate a specific browser (user agent header, cookie policy, etc).

If all else fails, you could write a small JavaScript controller and open that in a browser instead of the target web page directly. That JavaScript controller could then talk back to your application, get instructions (like what page to navigate to), and act on those. Selenium is a good candidate for that, but will probably require you to install a browser plugin.

Upvotes: 2

Related Questions