[solved] Focus On A Field In Internet Explorer

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
levisimcoe
Posts: 21
Joined: 03 Mar 2014, 19:37

[solved] Focus On A Field In Internet Explorer

03 Mar 2014, 19:41

What I'm trying to do is very basic. I apologize in advance as there appear to be many articles on this topic. I'm trying to focus on a field in a web browser (let's say Internet Explorer for example) by using the ID for that field and then send "test" to that field. I have tried clicking at coordinates but it is too unreliable when it comes to screen size, etc. I have tried tabbing, but I would prefer to get away from this.

I have tried using javascript, COM, and I can't seem to get anything to work.

Using the developer menu in Internet Explorer, I have selected the field that I am trying to focus on and have found the following attributes:
tabindex 1
id txtUserName

The window name according to windowspy is:
Report Exec - Windows Internet Explorer
ahk_class IEFrame
ClassNN: Internet Explorer_Server1

What would an example of the script I should be using to do this simple task? I have this:
ControlClick, txtUserName, Internet Explorer_Server1
ControlSend, Internet Explorer_Server1, test, Report Exec -

The above script will send "test" to whatever field I left selected.

I read the following article which got me onto javascript, which I couldn't get to work:
http://www.daviddele.../WebsiteNav.ahk

Among several other articles I read, I found this as well:
http://www.autohotke...variable-to-it/

What I'm looking for is an example of a script that I could use to select the field mentioned above and send the word "test" to it. Once I get that little bit to work, it will be quite easy to change one of my old scripts to fill out numerous fields.
Last edited by levisimcoe on 04 Mar 2014, 22:41, edited 1 time in total.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Focus On A Field In Internet Explorer

03 Mar 2014, 23:12

- Find out the exact name of the control ''txtUserName'' using WindowSpy.
- Focus this control using ControlFocus

Code: Select all

WinActivate, Report Exec - Windows Internet Explorer
WinWaitActive, Report Exec - Windows Internet Explorer
;Sleep, 100
ControlFocus, ''txtUserName'', A
ControlSend, ''txtUserName'', test, A
levisimcoe
Posts: 21
Joined: 03 Mar 2014, 19:37

Re: Focus On A Field In Internet Explorer

03 Mar 2014, 23:48

I tried the following script after reading your reply:
#t::
WinActivate, ahk_class IEFrame
WinWaitActive, ahk_class IEFrame
Sleep 1000
ControlFocus, ''txtUserName'', Report Exec - Windows Internet Explorer
ControlSend, ''txtUserName'', test, Report Exec - Windows Internet Explorer
No luck. Nothing gets sent. I tried taking out the quotation marks around txtUserName and also tried replacing them with `` thinking that it might make a difference. No such luck. No text is sent. As in my previous post, the exact name for the field is "txtUserName". When checking with Window Spy, I get nothing for the field. I included a screen shot of my Window Spy.

Please don't give up on me yet! Your help is really appreciated.
Attachments
Username Box.jpg
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: Focus On A Field In Internet Explorer

04 Mar 2014, 01:49

levisimcoe wrote:I have tried using javascript, COM, and I can't seem to get anything to work.
Can you post what you've tried?

Also, have you read through these tutorials?
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Focus On A Field In Internet Explorer

04 Mar 2014, 02:50

''txtUserName'' was meant only as an example to be replaced by the exact name of this control.

You find the exact name of the control if you hold the mouse pointer over it. The name of the control will appear then in WindowSpy as

>>>>>>>>>( Now Under Mouse Cursor )<<<<<<<<
ClassNN: ControlName?
User avatar
jethrow
Posts: 188
Joined: 30 Sep 2013, 19:52
Location: Iowa

Re: Focus On A Field In Internet Explorer

04 Mar 2014, 02:58

levisimcoe wrote:Using the developer menu in Internet Explorer, I have selected the field that I am trying to focus on and have found the following attributes:
tabindex 1
id txtUserName

The window name according to windowspy is:
Report Exec - Windows Internet Explorer
ahk_class IEFrame
ClassNN: Internet Explorer_Server1
levisimcoe already has the ClassNN. His issue is that he wants to focus on webpage element within that IE Control. He will need to utilize the HTML Dom for this (via javascript or COM), or tab thought the fields until he gets the correct one.

(ACC/UIA could be used as well, but a standard Dom call will be simpler)
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Focus On A Field In Internet Explorer

04 Mar 2014, 14:08

jethrow wrote:
levisimcoe wrote:Using the developer menu in Internet Explorer, I have selected the field that I am trying to focus on and have found the following attributes:
tabindex 1
id txtUserName

The window name according to windowspy is:
Report Exec - Windows Internet Explorer
ahk_class IEFrame
ClassNN: Internet Explorer_Server1
levisimcoe already has the ClassNN. His issue is that he wants to focus on webpage element within that IE Control. He will need to utilize the HTML Dom for this (via javascript or COM), or tab thought the fields until he gets the correct one.

(ACC/UIA could be used as well, but a standard Dom call will be simpler)
Perhaps an example that everyone has access to would be helpful.

Like how to type "jethrow" into the "Search for Author" field on the Search page of this forum using HTML Dom.

Unfortunately I cannot provide that example right off hand but maybe someone else can.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Focus On A Field In Internet Explorer

04 Mar 2014, 14:49

After some digging through my saved snippets, here is an example of Login code:

Code: Select all

Loginname = Your Name
Password = Your Password
URL = https://erpweb.terex.com/OA_HTML/ibeCAcdLogin.jsp

WB := ComObjCreate("InternetExplorer.Application")
WB.Visible := True
WB.Navigate(URL)
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10
wb.document.getElementById("ctl00_mainContentPlaceHolder_loginUserControl_userLoginTextBox").value := Loginname
wb.document.getElementById("ctl00_mainContentPlaceHolder_loginUserControl_passwordTextBox").value := Password
wb.document.getElementById("ctl00_mainContentPlaceHolder_loginUserControl_submitButton").click()
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
   Sleep, 10
Msgbox, Now logged in and loaded!
Hope it helps.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks
levisimcoe
Posts: 21
Joined: 03 Mar 2014, 19:37

[SOLVED] Re: Focus On A Field In Internet Explorer

04 Mar 2014, 21:34

FanaticGuru,

I gave your script a shot. I customized the URL and entered "test" for username and password. I then entered the customized element id's with those I obtained from the Internet Explorer developer tab. As soon as I ran the script I obtained an error. I attached a copy of the error screen that I obtained. This is very similar to the error codes that I kept getting with the other scripts I was testing "The Interface Is Unknown".

Some of the older posts that I found on this topic indicated that I needed AHK_L or the COM library installed. I attempted to find the COM library that was mentioned in many forums but all of the links were broken. I tried researching this topic and it seems that the newest version of AHK has these capabilities installed already. Is this correct or am I way off base? If this is correct, I suppose this would be why its not working for me.

I obtained very similar error codes when using COM scripts. Any help would be appreciated.

*EDIT* I have since researched the error code that I received and found that it was linked to "User Access Control". I shut off the control and the script works fine. Thank you very much for your help. I should have fun with this!
Attachments
Error.jpg

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, DiegoSouto, mikeyww, Rohwedder, Sniperman, Swiftly9767 and 393 guests