[Owasp-o2-platform] Problem with KeyPress, KeyDown or TypeText from o2 WatIn

Daniel Brzozowski daniel at brzozowski.biz
Tue Jun 7 19:44:12 EDT 2011


Hi Dinis,

Thanks! Invoking JS scripts solved my problem!

I somehow haven't thought about it...

 

I had to manipulate autocomplete plugin from O2 level - that's why I
couldn't use only TextField.value method.

Here is a script for IE Automation Tool to demonstrate what I wanted to
achieve - I used jquery autocomplete demo page to show it. 

panel.clear();
var ie = panel.add_IE().silent(true);

ie.open("http://jquery.bassistance.de/autocomplete/demo/");
//ie.invokeEval(incJquery);
ie.field("suggest1").value("London"); //entering value inside first
autocomplete control
ie.invokeEval("$('#suggest1').trigger('keydown')"); //triggering keyboard
event 
ie.wait(100);
ie.invokeEval("$('.ac_over:first').parent().click()"); //choosing first
value from autocomplete
return ie.fields();
//O2File:WatiN_IE_ExtensionMethods.cs
//using O2.XRules.Database.Utils.O2
//O2Ref:WatiN.Core.1x.dll

 

If jquery is needed - here is how I include latest version of jquery to the
page:

var incJquery = "var script = document.createElement('script');";
incJquery += "script.src = 'http://code.jquery.com/jquery-latest.pack.js';";
incJquery += "script.type = 'text/javascript';";
incJquery += "document.body.insertBefore( script, document.body.firstChild
);";

ie.invokeEval(incJquery);

 

Thanks again!

--

Regards,

db

 

From: dinis cruz [mailto:dinis.cruz at owasp.org] 
Sent: Monday, June 06, 2011 2:25 PM
To: daniel at brzozowski.biz
Cc: owasp-o2-platform at lists.owasp.org
Subject: Re: [Owasp-o2-platform] Problem with KeyPress, KeyDown or TypeText
from o2 WatIn

 

Hi Daniel, the WatiN/IE native methods sometime have problems handling
events (which I why more and more I'm doing some of this type of activity
directly on Javascript)

 

So, there are a couple ways you can do this:

*	directly entering the value on the field - did you try something
like: ie.field("fieldName").value("aaa");    depending on how the original
Javascript event hook is set-up that might just do the trick
*	directly invoking the javascript function that handles the KeyPress
- O2 has now quite extended support for Javascript, and you can easily
perform javascript invokes (and receive callbacks). See this links for more
details

*
http://o2platform.wordpress.com/2011/03/08/running-javascript-in-ie-automati
on-environment/
*
http://o2platform.wordpress.com/2011/03/31/o2-script-util-javascript-object-
viewer/
*
http://o2platform.wordpress.com/2011/03/07/o2-script-dwr-functions-viewer-an
d-invoker/

one note on Javascript, if you go down that route, I would advise you to
first inject jQuery.js into the page and then do your manipulations (since
you can write your Javascript code in jQuery which much easier) . There are
already good support for jQuery in O2 which you can leverage:

*	O2 jQuery API
<http://code.google.com/p/o2platform/source/browse/trunk/O2_Scripts/#O2_Scri
pts%2FAPIs%2F_Javascript_Libraries%2FJQuery> 
*	Util - Simple jQuery script GUI.h2
<http://code.google.com/p/o2platform/source/browse/trunk/O2_Scripts/APIs/_Ja
vascript_Libraries/JQuery/Util%20-%20Simple%20jQuery%20script%20GUI.h2> 
*	Util - XSS PoC Tester - Viewer.h2
<http://code.google.com/p/o2platform/source/browse/trunk/O2_Scripts/_Sample_
Vulnerabilities/Util%20-%20XSS%20PoC%20Tester%20-%20Viewer.h2> 

 

*	use Windows UIAutomation - at last resort you can move the mouse to
the location of the field (javascript/WatiN can help to find the screen
position) , then simulate a mouse click and finally enter some text (this is
basically using Windows to simulate your actions). See this script for an
example on how to the use White <http://white.codeplex.com/>  API (which is
the equivalent of WatiN by from Windows): PoC - Automating Notepad.h2
<http://code.google.com/p/o2platform/source/browse/trunk/O2_Scripts/APIs/Win
dows/White/PoC%20-%20Automating%20Notepad.h2> 

If you can, please post a sample script with your problem (and if you have
one) the solution

 

Dinis Cruz



On 6 June 2011 10:25, <daniel at brzozowski.biz> wrote:

Hi all,
I'm playing with O2 "IE Automation" tool and I need to simulate keydown
event on a textbox (can't use TextField.value() function). Everytime I try
to call KeyDown, KeyPress or TypeText I get reflection exceptions.
Does anyone know any workaround to this problem? Like executing javascript
on WatiN_IE object?


Stack Trace from log viewer:
[09:49:12] ERROR:      InnerException:    at
mshtml.HTMLDocumentClass.IHTMLDocument2_get_parentWindow()
  at WatiN.Core.UtilityClass.FireEvent(DispHTMLBaseElement element,
String eventName, NameValueCollection eventObjectProperties)
  at WatiN.Core.UtilityClass.FireEvent(DispHTMLBaseElement element,
String eventName)
  at WatiN.Core.InternetExplorer.IEElement.FireEvent(String eventName,
NameValueCollection eventProperties)
  at WatiN.Core.Element.fireEvent(String eventName, Boolean
waitForComplete, NameValueCollection eventProperties)
  at WatiN.Core.Element.FireEvent(String eventName)
  at WatiN.Core.Element.Focus()
  at WatiN.Core.TextField.TypeAppendClearText(String value, Boolean
append, Boolean clear)
  at WatiN.Core.TextField.TypeText(String value)
  at DynamicType.dynamicMethod(Object returnData, Panel panel)  StackTrace:

  at mshtml.HTMLDocumentClass.IHTMLDocument2_get_parentWindow()
  at WatiN.Core.UtilityClass.FireEvent(DispHTMLBaseElement element,
String eventName, NameValueCollection eventObjectProperties)
  at WatiN.Core.UtilityClass.FireEvent(DispHTMLBaseElement element,
String eventName)
  at WatiN.Core.InternetExplorer.IEElement.FireEvent(String eventName,
NameValueCollection eventProperties)
  at WatiN.Core.Element.fireEvent(String eventName, Boolean
waitForComplete, NameValueCollection eventProperties)
  at WatiN.Core.Element.FireEvent(String eventName)
  at WatiN.Core.Element.Focus()
  at WatiN.Core.TextField.TypeAppendClearText(String value, Boolean
append, Boolean clear)
  at WatiN.Core.TextField.TypeText(String value)
  at DynamicType.dynamicMethod(Object returnData, Panel panel)


[09:49:12] ERROR:      InnerException: Specified cast is not valid.
Specified cast is not valid.
[09:49:12] ERROR: in reflection.invokeMethod_InstanceStaticPublicNonPublic
 StackTrace:

  at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[]
arguments, SignatureStruct& sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
  at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[]
arguments, Signature sig, MethodAttributes methodAttributes,
RuntimeTypeHandle typeOwner)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture,
Boolean skipVisibilityChecks)
  at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags
invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
  at O2.Kernel.InterfacesBaseImpl.KReflection.invoke(Object oLiveObject,
MethodInfo methodInfo, Object[] methodParameters)


[09:49:12] ERROR: in reflection.invokeMethod_InstanceStaticPublicNonPublic
Exception has been thrown by the target of an invocation.


_______________________________________________
Owasp-o2-platform mailing list
Owasp-o2-platform at lists.owasp.org
https://lists.owasp.org/mailman/listinfo/owasp-o2-platform

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.owasp.org/pipermail/owasp-o2-platform/attachments/20110608/3b20278f/attachment-0001.html 


More information about the Owasp-o2-platform mailing list