Hi Brett-
The solution i came up with may be the long way around, and i can see 
some problem areas which need to be worked out, but essentially what i 
did was bastardize the show_all_objects to make a write_all_objects 
function, then parse and submit the resulting page with the following  
functions:

class WebPage
   # Parse the web page, extracting links to images

   def newpass(len)
    chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
    newpass = ""
    1.upto(len) { |i| newpass << chars[rand(chars.size-1)] }
    return newpass
   end
   
   def parse(host)
   dict = []
   newDict= []
    $i=0;
    $ie.write_all_objects("pageObject.txt")
    File.open("pageObject.txt") do |file|
        while line = file.gets
        dict[$i]= line.split
        $i =$i+1
        end
       end
       $j=0
            for x in dict do
               if x[0] == "text"  || x[0] == "checkbox"  || x[0] == 
"submit" || x[0] == "select-one" then
                 newDict[$j] = x
             $j=$j+1
               end#if  zeroith x is text
               #puts newDict
        end# every item in the dictionary
     return newDict
  end# parse page object
 
  def fillPageForms(host,newDict)
        for y in newDict do
        $id
        $value
            if y[1].include? "name" then
                $id =  y[1].gsub("name=", "")   
            elsif y[2].include? "id=" then
                $id =  y[2].gsub("id=", "")
            end
            if y[3].include? "value" then
                $value= y[3].gsub("value=", "")   
            end
            #check for field type
            if y[0] == "text" then
                  if $value != ""  then
                 host.text_field(:id, $id).set($value)
                else
                 host.text_field(:id, $id).set(newpass(8))
                end
            elsif y[0]=="checkbox" then
                host.checkbox(:value,$value).set
            elsif y[0] == "select-one" then
                host.select_list(:name, $id).select_value(/1/)
            elsif y[0] == "submit" then
                 if $value != "Clear Form" then
                       host.button(:name, $id).click
                  return
                 end
            end# check for field type
        end # for item in newDict   
   end  #fill page forms
end # web page class


I'd love comments and feedback.

Thanks--

Beth





Bret Pettichord wrote:

> At 12:53 PM 10/27/2005, beth ferguson wrote:
>
>> i've been trying to  write a function which dynamically finds all the
>> html elements on the page and then fills the form based on the found
>> html elements.
>>
>> So, in compete psuedo-code, i'd like to do something like
>> every field in pageObject do
>>     if field is textfield then
>>       get the name
>>       generate a value
>>       fill the field
>>    elsif field is button then
>>        / if submit then submit
>>    end
>> end.
>
>
> [...]
>
>> If am able to make this function I will be less tied to the particulars
>> of the gui, name, etc. Can anyone help me figure out what's wrong with
>> the above function or having already approached this problem, suggest to
>> me another angle.
>
>
> Something like this?
>
>   ie.text_fields.each {|tf| tf.value = tf.name.reverse}
>   ie.form(:index, 1).submit
>
> This enters the reversed name as the value of each text field (surely 
> you have a smarter idea for this). And then clicks the first submit 
> button.
>
>
> _____________________
>  Bret Pettichord
>  www.pettichord.com
>
>
>

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

Reply via email to