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

dinis cruz dinis.cruz at owasp.org
Wed Jun 8 14:44:18 EDT 2011


Hi Daniel,

Here is how you can achieve the same result using O2's native jQuery support
(I've posted more details on this blog post
http://o2platform.wordpress.com/2011/06/08/invoking-jquery-from-o2/):

  01 var topPanel = "PoC - jQuery IE Automation example"
.popupWindow(600,700);
  02 var ie = topPanel.add_IE().silent(true);
  03
  04 ie.open("http://jquery.bassistance.de/autocomplete/demo/<http://jquery.bassistance.de/autocomplete/demo/%3C/a>
");
  05 var jQuery = new IE_JQuery(ie);
  06 jQuery.id("suggest1")            // getting reference to html element
with id 'suggest1'
  07       .border(12)               // seeting the border value to 12
  08       .value("London")            // setting the 'value' attribute to
'London'
  09       .keydown();
  10
  11 jQuery.wait(200)                  // wait 200 ms to give time for the
'.ac_over:first' to exist
  12       .element(".ac_over:first")  // get reference to '.ac_over:first'
element
  13       .parent()                      // invoke the jQuery 'parent'
method
  14       .click();                      // invoke the jQuery 'click'
method
  15
  16 jQuery.wait(1000).id("suggest1").border(2);      // wait 1s before
removing the border</pre>
  17 return "ok";
  18
  19 //O2File:IE_JQuery.cs
  20 //O2File:WatiN_IE_ExtensionMethods.cs
  21 //using O2.XRules.Database.Utils.O2
  22 //O2Ref:WatiN.Core.1x.dll



Dinis Cruz

On 8 June 2011 01:19, dinis cruz <dinis.cruz at owasp.org> wrote:

> nice...
>
> Actually, you can simplify that a lot since you can already use O2 to
> inject the jQuery stuff :)
>
> Take a look at the jQuery API that is in O2 Scripts and see if you can
> figure out how to to use it.
>
> I'm off to the Phoenix chapter to present O2, so I if you still haven't
> figure it our later today let me know and I will post a code sample
>
> Dinis Cruz
>
> Blog: http://diniscruz.blogspot.com
> Twitter: http://twitter.com/DinisCruz
> Web: http://www.owasp.org/index.php/O2
>
>
>
> On 8 June 2011 00:44, Daniel Brzozowski <daniel at brzozowski.biz> wrote:
>
>> 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-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/20110608/749f102f/attachment-0001.html 


More information about the Owasp-o2-platform mailing list