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

    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?
    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks
    • Seminko
      By Seminko
      I am now able to populate the dropdown menus at https://www.tipcars.com/.
      The dropdowns are dynamic and do not have a Text value, only ids.
      Is there a way to get all the available options from a dropdown?
      $url = "https://www.tipcars.com/" $oIE = _IECreate($url) _IELoadWait($oIE) $oDownloadSamples = _IEGetObjById($oIE, "homepage_vyhl_frm_vozidlo") _IEFormElementOptionSelect($oDownloadSamples, "C") Above code, populates ID 'C' into the 'druh' dropdown, which results in selecting 'užitkové'. 
      Is there a way so I can grab all of the options from the dropdown menu? I could easily grab all the IDs but I am afraid they will change in the future so I would much rather match the text titles and assign the option IDs grabbed from site.
      This is what the options are according to Chrome:
      <select class="w1"id="homepage_vyhl_frm_vozidlo"name="homepage_vyhl_frm_vozidlo"onchange="try{NABIDKA_VOZIDEL_FORMULAR.naplnSelectZnacka('homepage_vyhl_frm');GLOBAL.pocetInzerceHZ('homepage_vyhl_frm','vozidlo');}catch(ex){odeslatJsChybu('formHOMEPAGE onChange 1: ' + ex.message, 'formHomePage onChange 1', -1);}"> <option value="A" style="color: black;">osobní a terénní (56 334)</option> <option value="C" style="color: black;">užitkové (4 333)</option> <option value="D" style="color: black;">nákladní (3 742)</option> <option value="E" style="color: black;">autobusy (56)</option> <option value="F" style="color: black;">obytné (373)</option> <option value="G" style="color: black;">přívěsy (1 179)</option> <option value="J" style="color: black;">motorky (780)</option> <option value="S" style="color: black;">pracovní stroje (605)</option> <option value="L" style="color: black;">ostatní (235)</option></select> Also, this cannot be grabbed by _INetGetSource.
      Thanks