0

Unable to delete text in textbox in squish tool using python. Anyone kindly support. d.clear() is not working, unable to clear entry in login username.need to clear all text characters in username field.

Tried delete, pop, clear, clean. Above mentioned things are not working.

d = mouseClick(waitForObject(names.main_view_login_username) 
d.clear()
d.pop()
d.del()
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
Srinivas R
  • 31
  • 2

3 Answers3

1
  1. Create a reference to the username field with waitForObject()

  2. Set the focus to it with setFocus()

  3. Clear its contents by typing an empty string with type()

username_field = waitForObject(names.main_view_login_username) 
setFocus(username_field)
type(username_field, "")
Victor Pop
  • 11
  • 2
1

The Python String isalnum() function determines whether or not a given string contains only alphanumeric characters. If all the characters are alphanumeric, it returns True; otherwise, it returns false if one or more characters are not.

    string = "Ge;ek * s:fo ! r;Ge * e*k:s !"
    
    test_str = ''.join(letter for letter in string if letter.isalnum())
    print(test_str)


In a loop, one can use str.replace() to find any bad chars and then replace them with the empty string to get rid of them. The simplest method is also the least effective in terms of performance.

# initializing bad_chars_list
bad_chars = [';', ':', '!', "*", " "]

# initializing test string
test_string = "Ge;ek * s:fo ! r;Ge * e*k:s !"

# printing original string
print("Original String : " + test_string)

# using replace() to
# remove bad_chars
for i in bad_chars:
    test_string = test_string.replace(i, '')

# printing resultant string
print("Resultant list is : " + str(test_string))

The bad character in the string is located using regular expressions, and the bad char is then replaced with another character using the re.sub function.

import re
 
# initializing string
test_str = "Ge;ek * s:fo ! r;Ge * e*k:s !"
 
# Bad character list
bad_char = [";", "!", "*", ":", " "]
 
# printing original string
print("The original string is : " + test_str)
 
# using re.sub()
# remove bad_char from string
temp = ''
for i in bad_char:
    temp += i
res = re.sub(rf'[{temp}]', '', test_str)
 
# printing result
print("The strings after extra space removal : " + str(res))
0

mouseClick() does not return a reference to your GUI object. So trying to use the return value usually does not make sense.

waitForObject() returns a reference to your GUI object. That object reference (in case of Squish for Qt and Squish for Java) has the native API of the associated GUI object available. You however try to call Python functions/methods, which are not available on these GUI object references.

If the object has a property that contains the text value, assigning "" to it usually works:

waitForObject(names.main_view_login_username).text = ""

Also the API of the object may offer a method to set the value:

waitForObject(names.main_view_login_username).setText("")

An option that is independent of the properties and methods is to use type() or nativeType():

type(waitForObject(names.main_view_login_username), "<Ctrl+a>")
type(waitForObject(names.main_view_login_username), "<Delete>")
type(waitForObject(names.main_view_login_username), "desired name value")

It should also be possible to record the desired actions, like selecting the complete contents (ideally via one key press, second best via multiple key presses, or for example via double click). Once recorded, altering/adjusting/improving the recorded script snippet is often easier.

frog.ca
  • 684
  • 4
  • 8