Jump to content

[SOLVED] Do/Does ToolTip interfere with focus?


ohaya
 Share

Recommended Posts

Hi,

I am still really new with AutoIT.  We are using it to automate logging into web sites and I have encountered problems with focus.  The target web page is configured to put the cursor into the first text field (username) when the page is loaded, and when I run the AutoIT script, which does the log in seems like it is just not starting where I expect it to be.  

I have been kind of using ToolTip() to kind of help with debugging, but now I am wondering if the calls to ToolTip() are causing the focus to be messed up.  

For example, at least visually, when the ToolTip() is called, I can see the cursor disappear from the web page text field and they when I do anything that is supposed to send keystrokes, they are going off somwhere else ("never-neverland").

But when I remove some of the ToolTip() calls, it works correctly.

So the questions I have are:

1) Do the ToolTip() calls interfere with/change where the focus on the target page are?

2) In general, what are the "rules" for where ToolTip can be used "safely" (== doesn't interfere with focus)?

Thanks,

Jim

 

Edited by ohaya
Add SOLVED to subject
Link to comment
Share on other sites

5 hours ago, FrancescoDiMuro said:

@ohaya
Hi, and welcome to the AutoIt forum :)

Did you take a look at _IE* functions? :)

 

Hi,

We got the original code I started with from a vendor and I have been working at that.  Actually they already were using the _IECreate() to start the IE instance, but I wasn't aware of the rest of the functions :).

Looking through those, is there a function to set the cursor back to first text field in a form?  

Would _IEFormReset do that?

If not, does one of the other functions do that?

 

Thanks!

 

Jim

Link to comment
Share on other sites

Hi @ohaya :)

Maybe it does, but, in case, you could give a try toevery function which get an instance of a DOM object, like _IEGetObjById().

Then, you could use _IEAction(YourObject, "focus"), to give focus to your element.

Let us know :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

I will look at using _IE more, but I guess that I still have the original question.  Does causing a Tooltip to appear interfere with the physical cursor on the browser? 

In other words, suppose the cursor is on the 2nd text field and then a ToolTip() is called.  When the actual tooltip gets displayed, does the cursor move/get lost?

Link to comment
Share on other sites

1 hour ago, FrancescoDiMuro said:

Hi @ohaya :)

Maybe it does, but, in case, you could give a try toevery function which get an instance of a DOM object, like _IEGetObjById().

Then, you could use _IEAction(YourObject, "focus"), to give focus to your element.

Let us know :)

Hi,

It looks _IEFormReset() does not cause the cursor/focus to move to the first field :(...

I did do some testing using _IEAction(<textFieldObject>, "focus) and that does appear to move the focus.

So I am thinking to try to get the list of objects for all the fields, but when I do that, is order of the field objects I get back always guaranteed to match the fields on the browser page?

 

Link to comment
Share on other sites

I am confused by something.

Suppose I know that there is always only one form on the page, so I get the collection of form elements like this:

Local $oIE = _IECreate($LOGIN_WEBPAGE,0,1,0,1)

Local $oForm = _IEFormGetObjByName($oIE, "form1")

Local $oElements = _IEFormElementGetCollection($oForm, 2)

 

But, now, how do I get a reference to the first element, so that I can then do the _IEAction and "focus"?  

 

Jim

 

 

Edited by ohaya
Link to comment
Share on other sites

Hi,

This works and causes focus to be on the "UserEmail" text field:

; THIS WORKS...
Local $oElement = _IEGetObjById($oIE, "UserEmail")
_IEAction($oElement "focus")

 

But, this doesn't seem to do anything:

Local $oElement = _IEFormElementGetCollection($oForm, 2)  <== the form has 4 elements 2 text fields and a checkbox and a button - I tried with 0, 1, 2, 3 but the focus never appears

_IEAction($oElement, "focus")

 

Link to comment
Share on other sites

Hi @ohaya :)

I think that it wasn't necessary to open a new post about this, since you provided every information the forum needs to help you ( this means that you would provide again the information about your script in the new post ).

By the way, let me answer you:

  • To get a Form object, you could use _IEFormGetObjById();
  • To get a Form element, you could use _IEFormElementGetObjByName();
  • To get any Form element ( of a given Form ), you could use _IEFormElementGetCollection(), with only the Form object parameter. If you want to get a SINGLE object from your Form using this function, then you have to specify the index of that element in the Form.

I higly reccomend you to use @error checking too, since, if there is an error in your script, it tells which function threw the error.

Not every function has an @error code, but most of them do have.

To check if there is an @error calling your functions, do something like this:

; Calling your function here
If @error Then
    ConsoleWrite("An error occurred calling FunctionName. Error: " & @error & @CRLF)
Else
    ; Keep with your code
EndIf

Try that ;)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

I *did* try _IEFormElementGetCollection(), with the index parameter, but as I said, when I tried that, it didn't appear to be working, e.g.:

Local $oElement = _IEFormElementGetCollection($oForm, $x)  

_IEAction($oElement, "focus")

did not cause the focus to be set on any of the text fields (and I tried running tests with $x set to different values, e.g., 0, 1, 2, etc.)

What I am hoping to do is to somehow be able to set the focus in the FIRST text field in the form, but without having to know what the text field name is.   The reason I want to be able to do this, is that otherwise, I would have to (a) know what the text field name is for every target, and (b) have a different AutoIT script for each target.

 

Link to comment
Share on other sites

5 hours ago, FrancescoDiMuro said:

@ohaya

Did you see if there is any error in the two functions above? :)

Hi,

Actually, after a bit of rest last night, I am testing and it looks like it is now working.  I added some debug logging to dump out the different attributes, and now figured out what the element is that I am getting:

        LogWrite(BANNER & "GOT the element [" & @error & "] $oElement.name=[" & $oElement.name & "] & id=[" & $oElement.id & "] & type=[" & $oElement.type & "]")
 

From that, it looks like if I search through the elements and find the first type=text element, that is the one that I need to set the focus on using _IEAction().

Thanks for all of your help!!

Jim

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...