Željko Filipin's Blog on Software and Testing

Test like you do not need the money.

Enter Non-English Character in Text Field

with 3 comments

google_zeljko.PNG

I use Watir a lot. I wanted to set a text field to željko. I did not know it would not be an easy task. I tried this code.

browser.text_field(:index, 1).set("željko")

But, text field was set to §eljko, Ĺľeljko, just eljko or some other string (depending if I try from irb, or from file that is saved in some encoding).

I searched wtr-general and found different solutions.

I added

require "win32ole"
WIN32OLE.codepage = WIN32OLE::CP_UTF8

and

$KCODE = 'utf8'
require 'jcode'

to the top of the file.

I tried TextField#value= instead of TextField#set.

browser.text_field(:index, 1).value=("željko")

I saved file as UTF-8.

Nothing worked. I sent my question to wtr-general and Paul Carvalho answered.

[...] I have a Watir script [...] It reads the inputs from an Excel file into an Array and then I use the array data to populate the text fields. [...] I didn’t use any special ‘require’ lines or KCodes. I just let Excel worry about holding the data [...]

I tried it, and it worked! It was simple, too. Just a few lines of code.

require 'watir'
excel = WIN32OLE::new('excel.Application')
workbook = excel.Workbooks.Open('C:\data.xls') # open file
worksheet = workbook.Worksheets(1) # the first worksheet
cell = worksheet.Range('a1')['Value'] # value of single cell
browser = Watir::IE.start('http://www.google.com/') # start IE
browser.text_field(:index, 1).set(cell) # set text field to value from cell

There is a page about scripting Excell, but it is unavailable at the moment. Fortunately, there is Google cache version.

Written by Željko Filipin

February 26th, 2007 at 3:48 pm

Posted in Watir

Tagged with

3 Responses to 'Enter Non-English Character in Text Field'

Subscribe to comments with RSS or TrackBack to 'Enter Non-English Character in Text Field'.

  1. You could probably also use an XML file and store the data in UTF8 format. I used to do that with VBScript.

    Frederic Torres
    http://www.InCisif.net
    Web Testing with C# or VB.NET

    Frederic Torres

    9 Nov 07 at 2:37 pm

  2. [...] had a look at the Watir mailing list and found a few people that were using excel to hold the UTF-8 word, getting the value from the cell, and passing it to [...]

  3. Thanks, this is useful.

    It should be noted that it appears you need a valid license for excel for this to work, otherwise, you will get an error message such as:

    cant open xls file unknown OLE server: `excel.Application’ (Exception)
    HRESULT error code:0x800401f3
    Invalid class string

    ref: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/290093

    (I’m going to adding some keywords, utf8, unicode, windows, watir, xls, IE, internet explorer, ie6)

    david wright

    28 Jul 09 at 1:46 am

Leave a Reply