[Owasp-o2-platform] How to set a text value into an html element?

Fabricio Braz fabricio.braz at gmail.com
Mon May 21 18:29:34 UTC 2012


Hello Dinis,

Thank you for the broad explanation.

I've tried the 1st, and it doesn't work. From that I went to 4th and
worked like a charm!

ie.invokeEval("document.getElementById('login_email').value =
'email at email.com'");
ie.invokeEval("document.getElementById('password_login').value = 'pass123'");
return ie.button("login").click();


Thanks,

Fabricio Braz

On Mon, May 21, 2012 at 11:05 AM, Dinis Cruz <dinis.cruz at owasp.org> wrote:
> Hi Fabricio
>
> There are a couple things that could be happening:
>
> The page load event might be triggered before the field exists (for example
> if that field is created via Javascript)
> The field is not really a field (in HTML), it could be something created via
> CSS
> The 'email' field type could not be recognized by WatiN (I had to say that
> it is the first time I've seen that input type)
>
> Here are a couple ideas for you to try:
>
> 1) introduce a delay after the page opens - this should help to clarify if
> the is is created by dynamic creation of fields:
>
> ie.sleep(1000);
> return ie.fields();
>
> you can also wait for a particular field/button/link to exists
>
> ie.waitForField('field name');
>
> or wait for a particular variable to exists
>
> ie.waitForJsVariable('variable name');
>
> 2) inject firebug-lite into the browser and use it to find the element
>
> ie.open("http://google.com");
> ie.inject_FirebugLite();
>
> and use firebug to find out what is going on (and maybe write the javascript
> required to make the manipulation you want)
>
> 3) inject firebug-lite and jquery
>
> ie.open("http://google.com");
> ie.inject_FirebugLite();
> ie.inject_jQuery();
>
> If you are a jQuery user/fan, this is the only way you can now manipulate
> Javascript  :)
>
> 4) manipulate the javascript from O2 script
>
> ie.eval("alert('hello from O2')");
>
> Here are a couple other variations (note how in the example below there is a
> two way communication channel between O2 the Browser
>
> ie.invokeEval("alert('hello again')");
> ie.invokeEval("aMethod = function(name) { return 'hello ' + name; } ");
> ie.invokeEval("alert(aMethod)");
> return ie.invokeScript("aMethod","'John Smith'");
>
>
> Finally, Fabricio, feel free to catch me on skype (DinisCruz) or GTalk, and
> I'l help you to figure out a way around it
>
> Dinis Cruz
>
> Blog: http://diniscruz.blogspot.com
> Twitter: http://twitter.com/DinisCruz
> Web: http://www.owasp.org/index.php/O2
>
>
> On 21 May 2012 13:35, Fabricio Braz <fabricio.braz at gmail.com> wrote:
>>
>> Hi there,
>>
>> I was trying to test a log in page, but O2 has not recognized the form
>> field "login_email".
>>
>> Just to make it clear, here are the steps I've done:
>>
>> - After loading the target page I run the following command:
>>
>> return ie.fields();
>>
>> - The page shows two fields (user login_email and password_login),
>> even though the O2 Output shows only the password_login field.
>>
>> - I started to look into the page elements ie.elements() and I found
>> the missed field. Here is an extract of it:
>>
>>     HTMLElement: System.__ComObject
>>     Id:
>>     Images: WatiN.Core.ImageCollection
>>     InnerHtml: <INPUT style="WIDTH: 200px; HEIGHT: 26px"
>> id=login_email name=email type=email>
>>     OuterHtml: <DIV class=input><INPUT style="WIDTH: 200px; HEIGHT:
>> 26px" id=login_email name=email type=email> </DIV>
>>
>>
>> - Since the element was identified, I thought that I could use the
>> setText to supply the user name I wanted to log in.
>>
>>     ie.elements()[28].set_Text("fabricio.braz at gmail.com");
>>
>> When I got the following error:
>>
>>     44::1::CS0311::The type 'WatiN.Core.Element' cannot be used as
>> type parameter 'T' in the generic type or method
>>
>> 'O2.DotNetWrappers.ExtensionMethods.WinForms_ExtensionMethods_Control_Object.set_Text<T>(T,
>> string)'. There is no implicit reference conversion from
>> 'WatiN.Core.Element' to
>>
>> 'System.Windows.Forms.Control'.::c:\Users\fabricio.braz\AppData\Local\Temp\eprso105.0.cs
>>
>> Considering the scenario above, could you help me set a text value
>> into the login_email field?
>>
>> Thanks in advance,
>>
>> Fabricio Braz
>> _______________________________________________
>> Owasp-o2-platform mailing list
>> Owasp-o2-platform at lists.owasp.org
>> https://lists.owasp.org/mailman/listinfo/owasp-o2-platform
>
>


More information about the Owasp-o2-platform mailing list