Sign in to follow this  
Followers 0
SlowCoder74

Bring a web element to focus

11 posts in this topic

I need to be able to auto-fill a form on a dynamic web page.  Depending on data entered, some fields may become enabled/or disabled.  Due to this, it is not a simple case of tabbing around a specific number of times to traverse the fields.

Is there a way to bring a specific field/element into focus based on its ID?  I am currently using Chrome to access the page, but if required, may be able to use IE.

Share this post


Link to post
Share on other sites



There are UDFs available for IE, FF, and Chrome.

Have you looked into using one of those to interact with the website?

Share this post


Link to post
Share on other sites

There are UDFs available for IE, FF, and Chrome.

Have you looked into using one of those to interact with the website?

Yes, I just found them.  I'm goofing with the IE one at this moment.

Share this post


Link to post
Share on other sites

After playing around, I'm having a terrible time just getting the code to attach to the proper IE instance.

I've created a sample HTML page:

<html>
<head><title>Test HTML</title></head>
<body>
    <form name="testform">
        <input type="radio" name="myradios" id="thisone"> click me!<br>
        <input type="radio" name="myradios" id="notthisone"> don't click me!<br>
    </form>
</body>
</html>

My AU3 code:

#include <IE.au3>

$IEhWnd = WinGetHandle("Test HTML","")
$oIE = _IEAttach($IEhWnd,"HWND") ;get IE instance via hWnd
;$oIE = _IEAttach("Test HTML","WindowTitle") ;get IE instance via window title
ConsoleWrite("$oIE=" & $oIE & ", Error=" & @error & @crlf)
$oForm = _IEFormGetObjByName($oIE, "testform") ;get form instance
ConsoleWrite("$oForm=" & $oForm & ", Error=" & @error & @crlf)
_IEFormElementRadioSelect($oForm, "myradios", "thisone") ;select the radio

In this project, the IE window will already be open.

My SCiTE console output when executed, attaching via the IE window's handle:

$oIE=, Error=0
--> IE.au3 V2.4-0 Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch
$oForm=0, Error=7
--> IE.au3 V2.4-0 Error from function _IEFormElementRadioSelect, $_IEStatus_InvalidDataType

My SciTE console output when attempting to attach via the window title:

$oIE=, Error=0
$oForm=, Error=0
--> IE.au3 V2.4-0 Warning from function _IEFormElementRadioSelect, $_IEStatus_NoMatch

In either instance, why are there no (visible) values assigned to the $oIE or $oForm variables?  I'm assuming something is getting assigned, because in the "WindowTitle" version, there is no error when retrieving the $oForm.

Share this post


Link to post
Share on other sites

Not sure that it matters... shouldn't the radio elements have values rather than ids?

Share this post


Link to post
Share on other sites

Not sure that it matters... shouldn't the radio elements have values rather than ids?

I tried it with value= instead of id=, and it made no difference.

 

They are of type "object", I doubt they have a printable value.

Understood.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

no problems here

#include <IE.au3>
$IEhWnd = WinGetHandle("Test HTML","")
$oIE = _IEAttach($IEhWnd,"HWND")
$oForm = _IEFormGetObjByName($oIE, "testform") 
_IEFormElementRadioSelect($oForm, "thisone", "myradios");note the diffrance from your code :P

<html>

<head><title>Test HTML</title></head>
<body>
    <form name="testform">
        <input type="radio" name="myradios" value="thisone"> click me!<br>
        <input type="radio" name="myradios" value="notthisone"> don't click me!<br>
    </form>
</body>
</html>

 

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites
_IEFormElementRadioSelect($oForm, "thisone", "myradios");note the diffrance from your code :P

 

LOL. Good catch!

Share this post


Link to post
Share on other sites

Ok, there were 2 problems with my code, then.  I didn't understand that it was looking for the value of the element.  And based on that lack of understanding, I was misinterpreting the parameters of the _IEFormElementRadioSelect command.

Thank you, everyone, for your help!

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  
Followers 0