Filling a textform - String too small?
I currently have to do a job where I have to copy the code of a website into a textfield.
I'm using watir to do the browser handling. As far as I know, I can only fill the field using the set
function, which means that I 开发者_Go百科have to do something like
browser.text_field(:id => "text").set sitetext
With sitetext
being the code of the website that I'm copying into it.
I've loaded the code from a file into an array before and then pushed it into the string (probably not the best choice, but easiest for me right now), using the following code.
contentArray=Array.new
inputFile=File.open("my-site.html")
inputFile.each{|line| contentArray<<line}
inputFile.close
Now when I execute the first command to fill in the text_field, it slowly types in all the letters (is there an easy way to speed this up?), but after 692 characters it stops in the middle of the sentence. [I pasted the text that was entered into charcounter.com, that's how I know this number.]
Where is the problem? Is ruby giving my strings a limited size for some reason? Can I somehow lift this barrier?
Is there another way to fill the text_field?
Try the .value method
browser.text_field(:id => "text").value=(open('my-site.html') { |f| f.read })
OR
I'm thinking the misprinting of umlauts etc is something to do with the codepage settings on your machine and the file you're reading from. You might have to experiment going from one code page to another ... I'm guessing your source file is CP850 or perhaps even UTF-8 and I think you need western european to get umlauts... but being Australian I really have no idea =) http://en.wikipedia.org/wiki/ISO_8859
e.g.
require 'iconv'
browser.text_field(:id => "text").value=(
Iconv.iconv('CP850', 'ISO-8859-1', open('my-site.html') { |f| f.read })
)
精彩评论