Sign in to follow this  
Followers 0
Jewtus

Unable to set value of IE Form element

33 posts in this topic

I'm trying to adapt the example

#include <IE.au3>

Local $oIE = _IE_Example("form")
Local $oForm = _IEFormGetObjByName($oIE, "ExampleForm")
Local $oText = _IEFormElementGetObjByName($oForm, "textExample")
_IEFormElementSetValue($oText, "Hey! This works!")

to work with a log in page and I'm not sure what I'm doing wrong and why its acting up.

This is what I tried:

#include <IE.au3>

Local $oIE = _IEAttach("C:\Test.html","Windowtitle")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

but it doesn't fill out the form.

Here is a snippet of the HTML of the form I'm working with:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<body>
<div class="opLogonBody">
<div class="left">
    <div class="opLogonComponent">

<div id="auth" class="security">
<form id="form_auth" action="BtoChannelDriver.ssobto?dse_contextRoot=true" method="post"  >
<div class="body">
<div class="superior">
<fieldset class="identificacion" id="identificacion"><legend>Data</legend>
<p>Please enter your logon information and press "Send"</p>
<div class="row"><label for="id_1">User:</label><input name="usuario" type="text" id="id_1"  maxlength="50" onfocus="idToWrite=&#9;id_1&#9;;pos=null" /></div>
<div class="row"><label for="clave">Password:</label><input type="password" name="password" id="clave"   maxlength="30" onfocus="idToWrite=&#9;clave&#9;;pos=null"/></div>
</fieldset>
</div>
</div>
<div class="foot"><span class="buttons"><input type="submit" value="Send"/></span><span class="link"><a href="" id="id_authenticateLink"></a></span></div>
</form>
</div>


    </div>
   </div>
</div>
</body>
</html>

Anyone know why it is not filling out the form?

Share this post


Link to post
Share on other sites



Reread the _IEAttach for a start.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This happens when I use IEcreate as well. 

#include <IE.au3>

Local $oIE = _IECreate("http://localhost:1234/test.html")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

If I was using attach incorrectly, so be it, but I don't actually care about the attach function. I saw trying to make it simpler so people don't have to save the HTML and load it into IIS. I tried IE create on a file path and it doesn't work, hence the use of IEAttach.

Edited by Jewtus

Share this post


Link to post
Share on other sites

 

>"C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:UsersArudolphDesktopNew AutoIt v3 Script.au3" /UserParams    

+>13:32:20 Starting AutoIt3Wrapper v.2.2.0.0 SciTE v.3.4.1.0   Keyboard:00000409  OS:WIN_81/  CPU:X64 OS:X64    Environment(Language:0409)
+>         SciTEDir => C:Program Files (x86)AutoIt3SciTE   UserDir => C:UsersArudolphAppDataLocalAutoIt v3SciTEAutoIt3Wrapper   SCITE_USERHOME => C:UsersArudolphAppDataLocalAutoIt v3SciTE 
>Running AU3Check (3.3.10.2)  from:C:Program Files (x86)AutoIt3  input:C:UsersArudolphDesktopNew AutoIt v3 Script.au3
+>13:32:21 AU3Check ended.rc:0
>Running:(3.3.10.2):C:Program Files (x86)AutoIt3autoit3.exe "C:UsersArudolphDesktopNew AutoIt v3 Script.au3"    
--> Press Ctrl+Alt+F5 to Restart or Ctrl+Break to Stop
--> IE.au3 T3.0-1 Error from function _IELoadWait, $_IEStatus_InvalidObjectType ()
--> IE.au3 T3.0-1 Warning from function _IEFormGetObjByName, $_IEStatus_NoMatch
--> IE.au3 T3.0-1 Error from function _IEFormElementGetObjByName, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
+>13:32:22 AutoIt3.exe ended.rc:0
+>13:32:22 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.885
 

Share this post


Link to post
Share on other sites

Ok... so the call to _IECreate failed. Did the web page load? You need to help yourself by providing more details so that we can help you.

Share this post


Link to post
Share on other sites

I don't believe adding another call to _IELoadWait will change anything (there is an inherent one in the _IECreate call).

When I run the code, it works as expected. The OP will need to provide more information in order to troubleshoot the issue.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Ok... so the call to _IECreate failed. Did the web page load? You need to help yourself by providing more details so that we can help you.

Yes, the IE window does show up but nothing gets entered into the form itself.

 

I don't believe adding another call to _IELoadWait will change anything (there is an inherent one in the _IECreate call).

When I run the code, it works as expected. The OP will need to provide more information in order to troubleshoot the issue.

I tried adding the IEloadwait and that didn't do anything. If it is working for you, I wonder if I have a corrupt IE.au3 script...

For more context:

When I run this script, IE pops up and then nothing else happens (his is what the IE window looks like when I run the script).

15cem4p.png

Edited by Jewtus

Share this post


Link to post
Share on other sites

Am not sure what you are doing wrong, but I just tried the script you posted using the HTML snippet, and it worked after I gave the webpage a title to attach to..

#include <IE.au3>

Local $oIE = _IEAttach("Hello World")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<title>Hello World</title>
<body>
<div class="opLogonBody">
<div class="left">
    <div class="opLogonComponent">

<div id="auth" class="security">
<form id="form_auth" action="BtoChannelDriver.ssobto?dse_contextRoot=true" method="post"  >
<div class="body">
<div class="superior">
<fieldset class="identificacion" id="identificacion"><legend>Data</legend>
<p>Please enter your logon information and press "Send"</p>
<div class="row"><label for="id_1">User:</label><input name="usuario" type="text" id="id_1"  maxlength="50" onfocus="idToWrite=&#9;id_1&#9;;pos=null" /></div>
<div class="row"><label for="clave">Password:</label><input type="password" name="password" id="clave"   maxlength="30" onfocus="idToWrite=&#9;clave&#9;;pos=null"/></div>
</fieldset>
</div>
</div>
<div class="foot"><span class="buttons"><input type="submit" value="Send"/></span><span class="link"><a href="" id="id_authenticateLink"></a></span></div>
</form>
</div>


    </div>
   </div>
</div>
</body>
</html>

Share this post


Link to post
Share on other sites

Am not sure what you are doing wrong, but I just tried the script you posted using the HTML snippet, and it worked after I gave the webpage a title to attach to..

#include <IE.au3>

Local $oIE = _IEAttach("Hello World")
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<title>Hello World</title>
<body>
<div class="opLogonBody">
<div class="left">
    <div class="opLogonComponent">

<div id="auth" class="security">
<form id="form_auth" action="BtoChannelDriver.ssobto?dse_contextRoot=true" method="post"  >
<div class="body">
<div class="superior">
<fieldset class="identificacion" id="identificacion"><legend>Data</legend>
<p>Please enter your logon information and press "Send"</p>
<div class="row"><label for="id_1">User:</label><input name="usuario" type="text" id="id_1"  maxlength="50" onfocus="idToWrite=&#9;id_1&#9;;pos=null" /></div>
<div class="row"><label for="clave">Password:</label><input type="password" name="password" id="clave"   maxlength="30" onfocus="idToWrite=&#9;clave&#9;;pos=null"/></div>
</fieldset>
</div>
</div>
<div class="foot"><span class="buttons"><input type="submit" value="Send"/></span><span class="link"><a href="" id="id_authenticateLink"></a></span></div>
</form>
</div>


    </div>
   </div>
</div>
</body>
</html>

That is strange... I just added the title as well and the attach call works. I'm not sure why it would be failing in the create call though...

Share this post


Link to post
Share on other sites

Unfortunately using the attach function didn't work on the site I'm trying to setup an auto login for. Anyone have any suggestions for how to setup an alternative auto login script against this?

Share this post


Link to post
Share on other sites

What site?

Share this post


Link to post
Share on other sites

Its an internal site for my company (it has client and employee data so the information is secure). They wont grant direct DB access which is why I have to go through the portal in the first place. Thanks anyway everyone.

Share this post


Link to post
Share on other sites

I stumbled across one of the problems... but not sure its the root cause.

When I get the form from the actual website, doesn't see a form. I was using example 3 of _IEFormGetCollection and I replaced the URL. When I did, the pop up said this page has 0 forms. I change the index to 1 and then it said there was 1 form, but it didn't output the name (like it did when I tried it against _IE_Example("form"))

How can I convert an object into something that I can look at to see what is going on... maybe dump it to a text file or something?

Share this post


Link to post
Share on other sites

Are there any iFrames involved?

Share this post


Link to post
Share on other sites

No iframes, but there are a number of scripts on the page (unfortunately, not ones I can share for security reasons). This is a screenshot of the basic HTML and how its structured.

Basically there is a HTML wrapped piece of HTML... its weird.

2efpd20.jpg

Share this post


Link to post
Share on other sites

The page contains frames. You need to first use _IEFrameGetObjByName to retrieve a reference to the desired frame. The use this reference in the _IEFormGetObjByName command instead of $oIE.

Share this post


Link to post
Share on other sites

I tried this:

Local $oIEattach = _IEAttach("Hello World")
local $oIE = _IEFrameGetObjByName($oIEattach, "___nav___"
;local $oIE = _IEFrameGetCollection($oIEattach, 1)
Local $oForm = _IEFormGetObjByName($oIE, "form_auth")
Local $oText = _IEFormElementGetObjByName($oForm, "usuario")
_IEFormElementSetValue($oText, "Hey! This works!")

I tried using get collection and using the name, but both ways still dont seem to work.

The console output is still saying that the _IEFormGetObjByName is getting no match. 

When I do this:

$oIEcreate = _IECreate(http://localhost:1234)
$oIE = _IEFrameGetCollection($oIEcreate,1)
Local $oForms = _IEFormGetCollection($oIE,1)
Local $iNumForms = @extended
MsgBox($MB_SYSTEMMODAL, "Forms Info", "There are " & $iNumForms & " forms on this page")
Local $oForm
For $i = 0 To $iNumForms - 1
    $oForm = _IEFormGetCollection($oIE, $i)
    MsgBox($MB_SYSTEMMODAL, "Form Info", $oForm.id)
Next 

It does detect the form, and it displays the form name. When I swap out the IEFrame with this one:

$oIE = _IEFrameGetObjByName($oIEcreate,"___nav___")

It fails to pull up the name but it does show up with the same count of forms.

I’m missing something fundamental here I think. When I comment out Local $oForms = _IEFormGetCollection($oIE,1) I get the following error

--> IE.au3 T3.0-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch

"C:Usersx345705DesktopDeleteme.au3" (29) : ==> Variable must be of type "Object".:

MsgBox(0,"SHOWUP",$oForm.id)

MsgBox(0,"SHOWUP",$oForm^ ERROR

 

And it kicks up a count of two forms as well as the name of the form.

So I tried tweaking it a little bit:

$oIE = _IEFrameGetCollection($oIEcreate,1)
Local $oForms = _IEFormGetCollection($oIE,1)
Local $iNumForms = @extended
MsgBox($MB_SYSTEMMODAL, "Forms Info", "There are " & $iNumForms & " forms on this page")
Local $oForm
For $i = 0 To $iNumForms - 1
    $oForm = _IEFormGetCollection($oIE, $i)
    MsgBox(0,"SHOWUP",$oForm.id)
Next

I get --> IE.au3 T3.0-0 Warning from function _IEFormGetCollection, $_IEStatus_NoMatch (which is likely because the first “form” doesn’t have a name..)

When I comment out the first msg box and run the script, no dialogs pop up. It’s like the first msgbox makes the script kick something up, but I’m getting really confused at this point.

Any suggestions?

Share this post


Link to post
Share on other sites

Are you sure that you have the correct frame? Generally, there will be more than one and I wouldn't expect a "nav" frame to hold the input forms. I would suggest looking at the example code for _IEFrameGetCollection and try running it against your web page. Post the results here.

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco
    • Omnitica
      By Omnitica
      Hello!
      I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.

      I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
      This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
      See image 1.
      However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
      See image 2.
      As you can see the value is 3982,4545     ( name , time )
      But when I try to change the value of it by doing:
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") The box doesn't get its new value. I  can see in the source that it's changed though.
      See image 3.
       
      However, if I do: 
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") $oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page The box gets its new value after the page reloads by the theForm.submit() function. 
      This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.
      Maybe someone knows how I can do this? Looking forward to an answer! 
      Thanks in advance.
       
      Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.
       



    • ur
      By ur
      For the below form, I am able to automate using below code for textboxes.

      #include <IE.au3> Local $oIE = _IEAttach("http://localhost:18170/MartAdmin/", "url") _IELoadWait($oIE) $Search = _IEGetObjById($oIE,"x-auto-16-input") _IEPropertySet($Search, 'innerText','Uday KIran') $Search = _IEGetObjById($oIE,"x-auto-18-input") _IEPropertySet($Search, 'innerText','Uday KIran') But for the Login button, there is no id or name.
      The html code when I click on Inspect element in browser, shown below.
      <button tabindex="0" class="x-btn-text" style="width: 64px; position: relative;" type="button">Log In</button> Please let me know how to click this.?
       
    • jonson1986
      By jonson1986
      Hey,
      I'm trying to select language from drop-down menu on a webpage by _IEGetObjById but it's  not working, It mean autoit open the page but unable to select my desired value not even by matching text or by value, I'm looking for kind help...I've pastes my Autoit codes below along with source codes(using ie) of the webpage ;
      #include <IE.au3> $site = "http://example.com/upload" $oIE = _IECreate($site) $oDownloadSamples = _IEGetObjById($oIE, "language") $oDownloadSamplesSelect = _IETagNameGetCollection($oDownloadSamples, "select", "language") $oDownloadSamplesSelect.focus _IEFormElementOptionSelect($oDownloadSamplesSelect, "French", 1, "byText") Sleep (1000) _IEFormElementOptionSelect($oDownloadSamplesSelect, "2", 1, "byValue") HTML Codes using IE:
      <html> <head> <div class="form-row"> <div class="col-7"> <label>Language</label> <select name="language" class="select" id="language"> <option value="1">English</option> <option value="2">French</option> <option value="3">German</option> <option value="4">Italian</option> <option value="5">Japanese</option> <option value="6">Spanish</option> <option value="7">Russian</option> <option value="8">Hindi</option> <option value="9">Arabic</option> <option value="10">Chinese</option> <option value="11">Dutch</option> <option value="12">Finnish</option> <option value="13">Korean</option> <option value="14">Norwegian</option> <option value="15">Portuguese</option> <option value="16">Romanian</option> <option value="17">Serbian</option> <option value="18">Croatian</option> <option value="20">Polish</option> <option value="21">Afar</option> <option value="22">Abkhazian</option> <option value="23">Afrikaans</option> <option value="24">Amharic</option> <option value="25">Assamese</option> <option value="26">Aymara</option> <option value="27">Azerbaijani</option> <option value="28">Bashkir</option> <option value="29">Belarusian</option> <option value="30">Bulgarian</option> <option value="31">Bihari</option> <option value="32">Bislama</option> <option value="33">Bengali/Bangla</option> <option value="34">Tibetan</option> <option value="35">Breton</option> <option value="36">Catalan</option> <option value="37">Corsican</option> <option value="38">Czech</option> <option value="39">Welsh</option> <option value="40">Danish</option> <option value="41">Bhutani</option> <option value="42">Greek</option> <option value="43">Esperanto</option> <option value="44">Estonian</option> <option value="45">Basque</option> <option value="46">Persian</option> <option value="47">Fiji</option> <option value="48">Faeroese</option> <option value="49">Frisian</option> <option value="50">Irish</option> <option value="51">Scots/Gaelic</option> <option value="52">Galician</option> <option value="53">Guarani</option> <option value="54">Gujarati</option> <option value="55">Hausa</option> <option value="56">Hungarian</option> <option value="57">Armenian</option> <option value="58">Interlingua</option> <option value="59">Interlingue</option> <option value="60">Inupiak</option> <option value="61">Indonesian</option> <option value="62">Icelandic</option> <option value="63">Hebrew</option> <option value="64">Yiddish</option> <option value="65">Javanese</option> <option value="66">Georgian</option> <option value="67">Kazakh</option> <option value="68">Greenlandic</option> <option value="69">Cambodian</option> <option value="70">Kannada</option> <option value="71">Kashmiri</option> <option value="72">Kurdish</option> <option value="73">Kirghiz</option> <option value="74">Latin</option> <option value="75">Lingala</option> <option value="76">Laothian</option> <option value="77">Lithuanian</option> <option value="78">Latvian/Lettish</option> <option value="79">Malagasy</option> <option value="80">Maori</option> <option value="81">Macedonian</option> <option value="82">Malayalam</option> <option value="83">Mongolian</option> <option value="84">Moldavian</option> <option value="85">Marathi</option> <option value="86">Malay</option> <option value="87">Maltese</option> <option value="88">Burmese</option> <option value="89">Nauru</option> <option value="90">Nepali</option> <option value="91">Occitan</option> <option value="92">(Afan)/Oromoor/Oriya</option> <option value="93">Punjabi</option> <option value="94">Pashto/Pushto</option> <option value="95">Quechua</option> <option value="96">Rhaeto-Romance</option> <option value="97">Kirundi</option> <option value="98">Kinyarwanda</option> <option value="99">Sanskrit</option> <option value="100">Sindhi</option> <option value="101">Sangro</option> <option value="102">Serbo-Croatian</option> <option value="103">Singhalese</option> <option value="104">Slovak</option> <option value="105">Slovenian</option> <option value="106">Samoan</option> <option value="107">Shona</option> <option value="108">Somali</option> <option value="109">Albanian</option> <option value="110">Siswati</option> <option value="111">Sesotho</option> <option value="112">Sundanese</option> <option value="113">Swedish</option> <option value="114">Swahili</option> <option value="115">Tamil</option> <option value="116">Telugu</option> <option value="117">Tajik</option> <option value="118">Thai</option> <option value="119">Tigrinya</option> <option value="120">Turkmen</option> <option value="121">Tagalog</option> <option value="122">Setswana</option> <option value="123">Tonga</option> <option value="124">Turkish</option> <option value="125">Tsonga</option> <option value="126">Tatar</option> <option value="127">Twi</option> <option value="128">Ukrainian</option> <option value="129">Urdu</option> <option value="130">Uzbek</option> <option value="131">Vietnamese</option> <option value="132">Volapuk</option> <option value="133">Wolof</option> <option value="134">Xhosa</option> <option value="135">Yoruba</option> <option value="136">Zulu</option> <option value="19">Other</option> </select> </div> </main> </body> </html>