Selenium typeKeys strips out dot from the String being typed

12,926

Solution 1

Have you tried using the Native key functions and javascript char codes? I couldn't get a 'period' character to work using them (char 190), but I got the decimal (char 110) to work just fine, and the text box shouldn't have a problem with either.

selenium.Focus("assigned_to");
selenium.Type("assigned_to", split[0]+"@");
selenium.TypeKeys("assigned_to", "gmail");
selenium.KeyPressNative("110");
selenium.TypeKeys("assigned_to", "com");

Solution 2

Use the type method.

From the javadoc for typekeys:

this command may or may not have any visible effect, even in cases where typing keys would normally have a visible effect

...

In some cases, you may need to use the simple "type" command to set the value of the field and then the "typeKeys" command to send the keystroke events corresponding to what you just typed.

Solution 3

We had similar problems using typekeys in selenium python.

One workaround we figured to resolve this issue is to use the combination of 'type' and 'type_keys'. As you might be aware, type does not have such issues.

We did this in our selenium python script and it works just fine.

For example: If there's an email address to be entered in a text box: [email protected]

Then do

type(locator,’[email protected].’)
type_keys(locator,’uk’)

Maybe a very crude way to do, but it did the job.

Hope this helps someone else with a similar problem.

Solution 4

Suppose the string to be typed using typeKeys is "abc.xyz.efg". Then, we can use type and typeKeys commands to write the given string.

type(locator,"abc.xyz.")
typeKeys(locator,"efg")

The above two steps are useful whenever you want to select an element in drop down box, and the drop down pops down only if we use typeKeys command.

Solution 5

Also try to set focus on element before write on it.

selenium.focus(locator);
selenium.typeKeys(locator, value);

it did function in my case, handling a input type=password.

Share:
12,926
Afamee
Author by

Afamee

Software QA Engineer with Alibris.com

Updated on June 06, 2022

Comments

  • Afamee
    Afamee almost 2 years

    The following instruction

    Selenium.typeKeys("location", "gmail.com");
    

    types the string gmailcom instead of gmail.com.

    What's happening there?

    From the comments:
    I am trying to simulate autofill and the only way to do it currently on selenium is to combine type and typeKeys. eg:

    selenium.type("assigned_to", split[0]+"@");
    selenium.typeKeys("assigned_to", "gmail.com");
    

    Now my question is why typeKeys doesn't type the 'dot' in between gmail.com?

  • Afamee
    Afamee about 15 years
    Believe me i read that doc. I am trying to simulate autofil and the only way to do it currently on selenium is to combine type and typeKeys. eg: selenium.type("assigned_to", split[0]+"@"); selenium.typeKeys("assigned_to", "gmail.com"); Now my question is why typeKeys doesnt type the 'dot' in between gmail.com?
  • guerda
    guerda about 15 years
    I added your comment to your question. Comments aren't read by everyone.
  • s_hewitt
    s_hewitt about 15 years
    I couldn't find any function in selenium that types a period (ASCII 46).
  • DerekD
    DerekD over 13 years
    Thats because you are using the Type method, the problem in the question is with the TypeKeys method.