Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Interacting with Internet Explorer

 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds awkward. Are you just after the source of a particular page, or do you need some functionality specific to IE?
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it using Robot Class
Thanks and Thanks a Lot!!!
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell me more about how you used Robot. With IE? Sounds interesting awright.
 
dinesh Venkatesan
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64824
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic