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

dinis cruz dinis.cruz at owasp.org
Mon Jun 6 09:24:44 EDT 2011


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-automation-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-and-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_Scripts%2FAPIs%2F_Javascript_Libraries%2FJQuery>
         - Util - Simple jQuery script
GUI.h2<http://code.google.com/p/o2platform/source/browse/trunk/O2_Scripts/APIs/_Javascript_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/Windows/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/20110606/c24b8051/attachment.html 


More information about the Owasp-o2-platform mailing list