Hi Paul,

I get the maxlength of a field the following way:

textfield = $ie.text_field(:id, $tf_userid)
object = textfield.getOLEObject()
maxlength = object.invoke("maxlength")

Hope this helps.

Ulrike

Paul Carvalho wrote:

> Most of my Watir scripts generate their own random inputs (content and 
> length), but I always have to specify an upper limit for each data 
> value specified.
>
> For example, a Create New User page has the following HTML for a User 
> Name input field:
>     <INPUT class=fieldLarge id=_ctl0_UserNameField maxLength=50 
> name=_ctl0:UserNameField>
>
> and the script writes to it with the following code:
>     # Input a username that is at least 5 characters but no more than 
> 50 chars in length
>     $ie.text_field(:name, /UserName/).set( random_input( 'text',  
> 5+rand(46) ) )
>
> So I have to [manually] specify in the script that it should contain 
> no more than 50 characters in length (i.e. upper limit of 5+45).
>
> I would like to know if it is possible to have Ruby/Watir 
> automatically read the 'maxLength=##' attribute and assign that value 
> to a variable that I can then work with in the corresponding input 
> commands?
>
> If I can do that, then my scripts will be even more independent and 
> free to generate their own inputs of random length based on what the 
> HTML says a field's upper limit is.
>
> I couldn't find anything in the Watir API Reference that looked like 
> it might do this.  Could we add a feature to do this if there isn't a 
> way now?
>
> Paul.
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Wtr-general mailing list
>[email protected]
>http://rubyforge.org/mailman/listinfo/wtr-general
>

_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to