Jump to content
Sign in to follow this  
Rishav

Set focus on a field in .Net App

Recommended Posts

Rishav

Hi

I am absolutely new to Autoit and am facing an issue which i am sure is quite easy. Googling or searching the forum didn't help me much as i suppose this is too basic.

I need to create an autoit script to login into a .net app.

Posted Image

when the screen is first opened, i need to set the focus on the Username field.

the code i used is

Run($client_Installed_path)
WinWaitActive("ABC Login")
ControlFocus ("ABC Login","Username","[ClassnameNN:WindowsForms10.EDIT.app.0.378734a1]")

but it doesn't works.

the windows summary for the field is

>>>> Window <<<<
Title:  Optima Login
Class:  WindowsForms10.window.8.app.0.378734a
Position:   369, 491
Size:   296, 189
Style:  0x16C80000
ExStyle:    0x00050101
Handle: 0x0014096C

>>>> Control <<<<
Class:  WindowsForms10.EDIT.app.0.378734a
Instance:   1
ClassnameNN:    WindowsForms10.EDIT.app.0.378734a1
Advanced (Class):   [CLASS:WindowsForms10.EDIT.app.0.378734a; INSTANCE:1]
ID: 1509956
Text:   
Position:   96, 32
Size:   176, 20
ControlClick Coords:    44, 15
Style:  0x560100C0
ExStyle:    0x00000200
Handle: 0x00170A44

>>>> Mouse <<<<
Position:   512, 560
Cursor ID:  0
Color:  0xFFFFFF

>>>> StatusBar <<<<

>>>> Visible Text <<<<
Server Login
Password
User ID
Data Source
&Cancel
&Login


>>>> Hidden Text <<<<

Any advices?

Also, will it be possible for me to use the field label as the control?

ie, can i write a script with the functionality 'Set focus on field where field label = "User Name"'

Finally,

I also tried the controlsend option which seemed more elegant to me than ControlFocus.

$user ="admin"
ControlSend("Optima Login","Data Source","[ClassnameNN:WindowsForms10.EDIT.app.0.378734a1]",$user)

it didn't work either. :/

thanks and regards

Rishav.

Edited by Rishav

Share this post


Link to post
Share on other sites
Rishav

Phew, after working the entire morning i finally managed to write one line of code. hurray me!

ControlFocus ("ABC Login","","[Class:WindowsForms10.EDIT.app.0.378734a;Instance:1]")

btw, can anyone help me with the other two questions?

Also, will it be possible for me to use the field label as the control?

ie, can i write a script with the functionality 'Set focus on field where field label = "User Name"'

Also for the last issue, i did manage to write text in the username field. but since there was some text already present there, it just appended the username to the text.

Finally,

I also tried the controlsend option which seemed more elegant to me than ControlFocus.

$user ="admin"
ControlSend("Optima Login","Data Source","[ClassnameNN:WindowsForms10.EDIT.app.0.378734a1]",$user)

it didn't work either. :/

Edited by Rishav

Share this post


Link to post
Share on other sites
PsaltyDS

Phew, after working the entire morning i finally managed to write one line of code. hurray me!

ControlFocus ("ABC Login","","[Class:WindowsForms10.EDIT.app.0.378734a;Instance:1]")
That is different from what you listed at first:

$user ="admin"
ControlSend("Optima Login","Data Source","[ClassnameNN:WindowsForms10.EDIT.app.0.378734a1]",$user)
Different window title, window text included, ClassnameNN used. On the control ID, what version of AutoIt are you using? I seem to recall a bug at one time for ClassNameNN with punctuation in it like "." in yours. It was fixed, but I don't remember at what version.

btw, can anyone help me with the other two questions?

No, the label is a separate static control with no relationship to the edit control you want, except by X/Y coordinates. You might try working of X/Y coordinates, but that shouldn't be necessary.

Also for the last issue, i did manage to write text in the username field. but since there was some text already present there, it just appended the username to the text.

ControlSetText() instead of ControlSend().

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites
Rishav

That is different from what you listed at first:

Different window title, window text included, ClassnameNN used. On the control ID, what version of AutoIt are you using? I seem to recall a bug at one time for ClassNameNN with punctuation in it like "." in yours. It was fixed, but I don't remember at what version.

No, the label is a separate static control with no relationship to the edit control you want, except by X/Y coordinates. You might try working of X/Y coordinates, but that shouldn't be necessary.

ControlSetText() instead of ControlSend().

;)

Thanks Psalty. that answers all my questions. :D

Share this post


Link to post
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
Sign in to follow this  

×