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
Member
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"+
		 "   element.click();\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
https://www.google.com/voice/#trash
on the element with id
gc-inbox-delete-forever

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
Misha

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>
</div>
</div>
</div>
</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: 2151
Registered: July 2009
Senior Member
Hi Misha, sorry for the late reply,

To confirm, you're expecting that element.click() 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 btnI.click() 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 element.click() 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());
display.dispose();
return;
}
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'); asdf.click();");
}
});
browser.setText("<html><body><input type=submit onclick=\"confirm('confirm?')\" id='asdf'></input></body></html>");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant
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
Member
Thank you so much.

Here is the solution FYI
http://www.webdeveloper.com/forum/showpost.php?p=1090875& ;postcount=15

I wrote a conformance test to figure it out.

The whole project is now on:
https://sourceforge.net/projects/webautomate/

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


Current Time: Thu Aug 22 09:40:46 GMT 2019

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

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

Back to the top