0

How can I do that in Java?

I want my application to programatically:

1) launch the Chrome browser to URL (I already know how to do this),

URI uri = new URI("http://www.example.com");
Desktop desktop = null;
if (Desktop.isDesktopSupported()) {
    desktop = Desktop.getDesktop();
}
if (desktop != null) {
    desktop.browse(uri);
    System.out.print("worked");
}

2) set the user agent (stuck on doing this)

3) set proxy. (and this)

4) fill out some form data and complete some other functions

5) repeat

Im stuck. Is this possible for a java application to do? I was using HtmlUnit at first to load the webpage and submit form data and complete some actions through that, BUT certain Javascripts don't load, that regular browsers do, I need that functionality.

This is an OSX specific application.

Thanks.

user294446
  • 81
  • 1
  • 1
  • 5

1 Answers1

0

If you use the Desktop class, it opens the default browser. If you change the default browser the Desktop.browse will launch that instead of Chrome. If you want chrome, try something different like running an external program. This question explains how

It seems that you can not change the user agent of chrome from the command line. You can add extensions to chrome to change the command line but you have to do it using the user interface. If you need to change the user agent every time, it will be a problem.

HtmlUnit has limited javascript support as they say in the htmlunit page

You could try to find a way to use the Webkit engine in java. It can do everything you need.

Community
  • 1
  • 1
Alejandro Vera
  • 377
  • 2
  • 12