How to check text box is having content or not??

Asked by Saorabh Singh

Hi,
i am using Sikuli in my java program.on windows
i have a requirement to enter some Content in text box...Suppose USer name
but if User name is already there then::
we have to either skip entering data entry in text box or Replace it with different username.

So, my question is how can we determine that textbox is not empty..
because in my code..
m looking for blank_textbox.png
So i thougt if this fails that means text box is not empty..

But Sikuli is able to serach: non empty text box...even with blank_textbox.png
& later it enter username...which append it with existing user name & this results in to faliure..as this was not expected...

help me out with this...

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Calle Rundgren (c-rundgren) said :
#1

answer = input("do you want to replace an existing username?") #first ask about what to do
userName = input("input your username")
if answer == "yes": #in case answer is yes
    find("blank_textbox.png") #find the location of the textbox
    click(getLastMatch()) #click latest found match (textbox)
    type("a", Key.CTRL) #highlight the text in textbox (if there is any)
    paste(userName) #paste the username.
if answer == "no":
    type(Key.ENTER) #press enter to logon (or whatever you want do)

Is it something liek this you are looking for?

Revision history for this message
RaiMan (raimund-hocke) said :
#2

If the entry field is empty, the returned match of find(blank_textbox.png) should have a score of nearly or exactly 1.0.

If the entry field contains some text, it depends on the blank_textbox.png, but if it succeeds, it should have a score markedly below 0.9.

So you can use the match's score to distinguish the 2 situations.

example (to be translated to correct Java ;-)

Match m = s.find("blank_textbox.png")
if m.getScore() > 0.95 # textbox empty
else: # textbox filled

Revision history for this message
Saorabh Singh (kunnu30) said :
#3

hi,
thanks for Answer.
but m.getScore() isnot Available in java,
So do we have any other Equivalent function which can be used in java??

On Thu, Jun 16, 2011 at 7:01 PM, RaiMan <
<email address hidden>> wrote:

> Your question #161652 on Sikuli changed:
> https://answers.launchpad.net/sikuli/+question/161652
>
> RaiMan proposed the following answer:
> If the entry field is empty, the returned match of
> find(blank_textbox.png) should have a score of nearly or exactly 1.0.
>
> If the entry field contains some text, it depends on the
> blank_textbox.png, but if it succeeds, it should have a score markedly
> below 0.9.
>
> So you can use the match's score to distinguish the 2 situations.
>
> example (to be translated to correct Java ;-)
>
> Match m = s.find("blank_textbox.png")
> if m.getScore() > 0.95 # textbox empty
> else: # textbox filled
>
> --
> If this answers your question, please go to the following page to let us
> know that it is solved:
> https://answers.launchpad.net/sikuli/+question/161652/+confirm?answer_id=1
>
> If you still need help, you can reply to this email or go to the
> following page to enter your feedback:
> https://answers.launchpad.net/sikuli/+question/161652
>
> You received this question notification because you asked the question.
>

Revision history for this message
Best RaiMan (raimund-hocke) said :
#4

it definitely is available for a Match object!

http://sikuli.org/doc/java-x/org/sikuli/script/Match.html

Revision history for this message
Saorabh Singh (kunnu30) said :
#5

Thanks Raiman