Forum: Ruby watir browser.button umlaut problem

Posted by unknown (Guest)
on 2012-07-15 19:28
(Received via mailing list)
Hi all



I am automating some simple Web application testing using watir, i e
clicking on browser buttons, selecting an item from a dropdown list etc.
Everything I got working except the following.

The script should click on browser buttons that contain Umlaut 
characters in
its name (German  for example). Example of a button name "Whle 6
Zufallszahlen"



Problem: The script exists with the following error

C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/el
ement.rb:66:in `assert_exists': Unable to locate element, using
{:tag_name=>["button", "submit", "image", "reset"], :value=>"W\xE4hle 6
Zufallszahlen"} (Watir::Exception::UnknownObjectException)



---- Begin script extract
-------------------------------------------------------------------

#encoding: ISO-8859-1

require 'watir'



browser = Watir::Browser.start "http://gahq.hopto.org/lotto/lotto.php"



  browser.button(:value,"Whle 6 Zufallszahlen").click

----End script extract
--------------------------------------------------------------------



I thought the #encoding ISO-8859-1 ... at the beginning could help. 
Without
this line (or encoding set to UTF-8 etc) the script would exit with the
error

ruby-lotto4b.rb:18: invalid multibyte char (US-ASCII)

ruby-lotto4b.rb:18: syntax error, unexpected tIDENTIFIER, expecting ')'
browser.button(:value,"Whle 6 Zufallszahlen").click



I searched the forum archive, but couldn't spot any information how-to
resolve the problem.



Has someone encountered the problem as well and found a solution?

I am using Ruby 1.9.3-p194  on Win7, browser IE9



Regards

Alex Schubert
Posted by Bartosz Dziewoński (matmarex)
on 2012-07-15 21:20
(Received via mailing list)
Make sure that the webpage and your script are encoded in the same
encoding. Then make sure the #encoding: line mentions the same
encoding as well.

Looks like the site is in iso-8859-1 – is your script?

-- Matma Rex
Posted by Alex Schubert (Guest)
on 2012-07-21 09:38
(Received via mailing list)
Hi all



I didn't manage to solve the problem itself, but you may be interested 
in
knowing that I found a workaround.

I figured out howto use regular expressions for object recognition, in 
this
case the browser button name.

Search for a substring of the button name, which does not contain an 
Umlaut
character and uniquely identifies it.



Example



  if browser.button(:value, /hle 6 Zufallszahlen/).exist?

    browser.button(:value, / hle 6 Zufallszahlen /).click

  end



regards

Alex



Von: a.schubert@datacomm.ch [mailto:a.schubert@datacomm.ch]
Gesendet: Sonntag, 15. Juli 2012 19:28
An: ruby-talk ML
Betreff: watir browser.button umlaut problem



Hi all



I am automating some simple Web application testing using watir, i e
clicking on browser buttons, selecting an item from a dropdown list etc.
Everything I got working except the following.

The script should click on browser buttons that contain Umlaut 
characters in
its name (German  for example). Example of a button name "Whle 6
Zufallszahlen"



Problem: The script exists with the following error

C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-classic-3.0.0/lib/watir-classic/el
ement.rb:66:in `assert_exists': Unable to locate element, using
{:tag_name=>["button", "submit", "image", "reset"], :value=>"W\xE4hle 6
Zufallszahlen"} (Watir::Exception::UnknownObjectException)



---- Begin script extract
-------------------------------------------------------------------

#encoding: ISO-8859-1

require 'watir'



browser = Watir::Browser.start "http://gahq.hopto.org/lotto/lotto.php"



  browser.button(:value,"Whle 6 Zufallszahlen").click

----End script extract
--------------------------------------------------------------------



I thought the #encoding ISO-8859-1 ... at the beginning could help. 
Without
this line (or encoding set to UTF-8 etc) the script would exit with the
error

ruby-lotto4b.rb:18: invalid multibyte char (US-ASCII)

ruby-lotto4b.rb:18: syntax error, unexpected tIDENTIFIER, expecting ')'
browser.button(:value,"Whle 6 Zufallszahlen").click



I searched the forum archive, but couldn't spot any information how-to
resolve the problem.



Has someone encountered the problem as well and found a solution?

I am using Ruby 1.9.3-p194  on Win7, browser IE9



Regards

Alex Schubert
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.