Forum Discussion

Viji123's avatar
Viji123
Occasional Contributor
8 years ago

Issue in SetText() method

I wrote python script for a simple test scenario. Have to enter username and password in the edit box. I used the below code

username.SetText("admin")

password.Keys("abcdef")

save_button.Click()

 

When i run this , it enters the username, password and when it comes to click the save button the username got wiped off . Dont know how or why.

 

In the same example if i use username.Keys("admin") , the script works fine. Can anyone let me know why the SetText() is behaving differently in this scenario

 

 

5 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    SetText frequently behaves differently than Keys.  SetText is trying to set the field to the given value and Keys is just typing as if someone was using the keyboard.

     

    SetText may or may not work (as you have seen) depending on the field you are using it on.  There may be validation or other code behind the scenes that is keeping it from working.  Keys will work consistently and we've switched to always using that for text fields.

    • Manfred_F's avatar
      Manfred_F
      Regular Contributor

      It's true, simple things are sometimes more complicated than one would think.

       

      In my own SetText function, I do the following:

       

      determine a second control to activate

      repeat

        set Focus to field

        set the .wText property

        set Focus to 2nd control

        check for msgboxes

        check .wText of field

      until field has correct .wText or msgbox shown or nr. of iterations too large

       

      The SetFocus function also deals with overlapping Windows.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        In the application we're testing, we can't use "SetText" for login processes to our application.  There is security stuff on the login page that does not allow for a forced "set" of the text property of the controls.  We have to use the "Keys" method.

        Please try replacing "SetText" with Keys and go from there.