Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Help simulating mouse click in SWT browser?
Help simulating mouse click in SWT browser? [message #535390] Sun, 23 May 2010 03:08 Go to next message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Dear All:

For what its worth I have a strange problem. I am using the following Javascript to simulate a mouse click:
"if (element.tagName=='INPUT') {\r\n"+
		 "} else {\r\n"+
		 "   if (document.createEvent) {\r\n"+
		 "      var evObj=document.createEvent('MouseEvents');\r\n"+
		 "      evObj.initEvent('mousedown',true,false);\r\n"+
		 "      element.dispatchEvent(evObj);\r\n"+
		 "      evObj.initEvent('mouseup',true,false);\r\n"+
		 "      element.dispatchEvent(evObj);\r\n"+
		 "   } else if (document.createEventObject) {\r\n"+
		 "      element.fireEvent('onmousedown');\r\n"+
		 "      element.fireEvent('onmouseup');\r\n"+
		 "   }\r\n"+

Specifically, this is on
on the element with id

On Firefox/Ubuntu (SWT Browser), this works quite well and the desired popup (window.confirm) pops up, which I can easily block with:
window.confirm=function(msg) { return true; }

However, on IE/Windows (SWT Browser), the popup _does not_ come up. However, I can see that the SWT Browser window loses focus, and further:
i) if I manually click on the button, the popup comes up
ii) if I simulate a mouse click using the Display widget, it _also_ comes up (unfortunately, the latter does _not_ work with the window hidden).

Further, no WindowEvents of any kind are generated.

I am quite stumped. I would like to simulate a click and have the popup appear.

Any help much appreciated.

Thank you

p.s. I am quite a newbie when it comes to Javascript, but, for what its worth, here is the relevant HTML for the button. Perhaps there is some way to simulate the event without simulating a click? I am not clear as to what actually causes the event to occur (no onclick action etc.) Thank you!
<div id="gc-inbox-delete-forever" class="goog-inline-block goog-button goog-button goog-button-base goog-button-base-collapse-right" style="-moz-user-select: none;" role="button">
<div class="goog-inline-block goog-button-base-outer-box">
<div class="goog-inline-block goog-button-base-inner-box">
<div class="goog-button-base-pos">
<div class="goog-button-base-top-shadow"> </div>
<div class="goog-button-base-content">Delete Forever</div>
Re: Help simulating mouse click in SWT browser? [message #537169 is a reply to message #535390] Tue, 01 June 2010 14:33 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi Misha, sorry for the late reply,

To confirm, you're expecting that should "press" the button, right? The first thing you should do is put an alert('hi') there to ensure that the path you think is running is actually running.

I'm not able to try your specific case because Google Voice accounts are not available outside of the U.S., but I've confirmed on the main google page that works for me in IE (the I'm Feeling Lucky button). If this works for you but the Google Voice page does not then there's probably either an IE security setting getting in the way or a bug in the Browser control.

The following snippet tries the basic case of showing a confirm when a submit element is click()ed. Its intent is to determine if the Browser fails to show confirm prompters in response to in the general case, but it seems fine for me. Does it work for you?

public static void main(String [] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
final Browser browser;
try {
browser = new Browser(shell, SWT.NONE);
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " + e.getMessage());
browser.setLayoutData(new GridData(400,400));
Button button = new Button(shell, SWT.PUSH);
button.setText("click the html button");
button.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
browser.execute("var asdf = document.getElementById('asdf');;");
browser.setText("<html><body><input type=submit onclick=\"confirm('confirm?')\" id='asdf'></input></body></html>");
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();

Re: Help simulating mouse click in SWT browser? [message #537273 is a reply to message #537169] Tue, 01 June 2010 18:26 Go to previous message
Misha Koshelev is currently offline Misha KoshelevFriend
Messages: 31
Registered: May 2010
Thank you so much.

Here is the solution FYI ;postcount=15

I wrote a conformance test to figure it out.

The whole project is now on:

Previous Topic:IStructuredSelection thoughts
Next Topic:SWT Browser Example - RCP Application
Goto Forum:

Current Time: Fri Dec 13 00:34:08 GMT 2019

Powered by FUDForum. Page generated in 0.02739 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top