I cannot figure out how to enter the Chinese characters into the textfield of a webpage by firewatir 1.6.5, I tried to change the encoding of the .rb file and the encoding of the firefox browser, but failed.
require ‘rubygems’
require ‘firewatir’
ff = FireWatir::Firefox.new
ff.goto “http://www.google.com“
sleep 1
ff.text_field(:name, ‘q’).set(‘?’)
For Watir 1.6.5, the Chinese charaters can be supported by replacing the script WIN32OLE.codepage = WIN32OLE::CP_UTF8 with WIN32OLE.codepage = WIN32OLE::CP_ACP in the file of C:\Ruby\lib\ruby\gems\1.8\gems\watir-1.6.5\lib\watir\win32ole.rb
We can check the version of the watir and firewatir by executing an rb file with the following script:
require ‘watir’
require ‘firewatir’
puts Watir::IE::VERSION
puts FireWatir::Firefox::VERSION
Maybe it is safe to add the code of require ‘rubygems’ in the beginning of the watir codes, otherwise, strange results may happen sometimes .
Just copy a coding found in the internet for future reference,
$ie.divs.collect {|div|
if div.class_name == “data”
puts div.text
end
}
It is quite slow to fill a text field by ie.text_field().set(content), the fast way is by ie.text_field().value = content.
I encountered an iframe in a webpage which say “iframe class = “the_iframe”, I tried but failed to access the iframe by:
ie.frame(:class, “the_iframe”)
and then I figured out there is no property of class for iframe in watir, and find the iframe by index:
ie.frame(:index, 1)
we can use ie.show_frames to find how many frames are there in a webpage.