Reply
Highlighted
Occasional Contributor
Posts: 7
Registered: ‎10-21-2016

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

 

 

Trusted Contributor
Posts: 1,272
Registered: ‎07-18-2013

Re: Issue in SetText() method

[ Edited ]

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.

Regular Contributor
Posts: 206
Registered: ‎05-19-2014

Re: Issue in SetText() method

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.

Posts: 3,281
Topics: 29
Kudos: 880
Solutions: 171
Registered: ‎11-30-2009

Re: Issue in SetText() method

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.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Extensions available
Community Leaders Program
Trusted Contributor
Posts: 1,272
Registered: ‎07-18-2013

Re: Issue in SetText() method

Wow, now we've given the same answer three times in row, shall we try for four?

Posts: 3,281
Topics: 29
Kudos: 880
Solutions: 171
Registered: ‎11-30-2009

Re: Issue in SetText() method


Marsha_R wrote:

Wow, now we've given the same answer three times in row, shall we try for four?


LOL...  It's been a weird day for me otherwise I would have caught that duplication..  at least we're consistent, yes? Smiley Happy


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Extensions available
Community Leaders Program
Register Now