File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Interacting with Internet Explorer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Interacting with Internet Explorer" Watch "Interacting with Internet Explorer" New topic
Author

Interacting with Internet Explorer

dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi All,

I tried using "exec()" to invoke the Internet Explorer. Now I want to interact with the IE such as opening an html file, click the view source, etc., In short I want to invoke some other menus of the IE. Is it possible with a Java Program. Does Java support such kind of operations. I want to access my local machine only not in a network.

Thanks in Advance!!!
dinesh.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sounds awkward. Are you just after the source of a particular page, or do you need some functionality specific to IE?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
I need to invoke the functionalities of IE.
That is using exec() i can simply invoke the Internet Explorer.. Now i want to load a particular page such as test.html which is stored in my local drive..

Thanks in Advance!!!
dinesh.
Stephen Foy
Ranch Hand

Joined: Oct 17, 2005
Posts: 143
You could try using something from the KeyEvents class. To send the keys of shortcuts to internet explorer. "CTRL-N" to open a new window.

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/event/KeyEvent.html


Stephen Foy - Microsoft Application Development Consultant
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

No, you'll need to invoke some native technology to interact with the browser window, since Java has no access to it, beyond running IE. Off the top of my head I can't think of an easily available one. You might try browsing MSDN to find something suitable.
[ January 11, 2007: Message edited by: Paul Sturrock ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I did a Google on "win32 sendkey script" and got a lot of hits. We've been looking at some expensive commercial products that do a bang up job of this kind of thing: OpenSpan, Jacada, eGlue. Any GUI test tool should be able to do what you're after ... maybe you can extract some parts of one of those. A simple VB script might take you far enough, too. Let us know what you find!


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Isn't it possible, to use awt.Robot, to move the mouse and send events to other applications?

IE has an option to start with a specific page, like

That's pseudocode. See the fine manual for the real command.


http://home.arcor.de/hirnstrom/bewerbung
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

I would like to know what the actual requirements are here. In other words, why would you want to do that? Your original post suggests you want to get at the source code of an HTML page from the web somewhere, and for that you don't need to remote-control that hulking robot IE. You can access the code directly and easily using classes in the java.net package.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Paul,

Thanks. My original requirement is i would like to generate some HTML files through my program after that i have to invoke them that means i have to Load the pages through my program not by requesting the user to double click the HTML file.

dinesh.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

OK, then see Stefan's post above. You can easily specify the document to open when you launch IE. Don't make this so complicated!


[Jess in Action][AskingGoodQuestions]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18127
    
    8

You can also run the Windows shell command START to load an HTML file in the computer's default browser (which might not be IE):

START \path\to\the.html
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi Stephan and Paul,

Thanks for your ideas. It works from my command prompt as an external command but when try to run from the Java Program using exec. Its not working.

java.io.IOException: CreateProcess: start C:/test.html error=2
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at Explorer.main(Explorer.java:4)

Getting the following error.
So now trying using the Robot Class.
Will update you about the results.
Thanks,
dinesh.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
I got it using Robot Class
Thanks and Thanks a Lot!!!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Tell me more about how you used Robot. With IE? Sounds interesting awright.
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
Hi All,

Sorry for late response as i was in holiday.

Using the Robot i simulated the keyPress(VK_WINDOWS);
then keyPress(VK_R);

which pops up the run prompt. Then i simulated a series of key press events.

VK_I
VK_E
VK_X
VK_P
VK_L
VK_O
VK_R
VK_E

VK_ENTER

this resulted in invoking the IE. After using the mouseMove(15,15);
i made the mouse to move to the File menu.

then simulated the mousePress() and mouseRelease() causing the mouse click on File menu.. like that i interacted.

regards,
dinesh.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60053
    
  65



[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interacting with Internet Explorer
 
Similar Threads
new browser detection
How to invoke the password manager
output in firefox
Can I make a toolbar that can be added as an Add on for Internet Explorer?
EJB from HTML