views:

62

answers:

1

I am currently using Watir with Firefox and it seems that when I try to set a field with the following text:

!@#$QWER7890uiop

The command I am using is the following:

text_field(:name, "password").value=("!@#$QWER7890uiop)

I've also tried this:

text_field(:name, "password").set "!@#$QWER7890uiop)

Only the first 2 characters get entered. Is there something I can do to by pass this feature?

+3  A: 

You need to escape the string using single quotes '.

text_field(:name, "password").value='"!@#$QWER7890uiop'

Many characters are substituted inside double quotes.

  1. Escape sequences like \n, \t, \s, etc are replaced by their equivalent character(s). See here for full list.
  2. #{} where anything the braces is interpreted as a ruby expression.
  3. #$something where $something is interpreted as a ruby global variable. That's the problem with your quote above, beside not being terminated.
  4. %s is interpreted as an ERB template expression (it is interpolated). For instance:
    puts "%s hours later" % 'Five'
    results in
    "Five hours later".
Alkaline
Which characters need to be escaped? Is it the! That causes issues?
Woot4Moo
I've just added the list I know of on the answer above.
Alkaline