MeAgain

Object lost at second web page

18 posts in this topic

#1 ·  Posted (edited)

Hi everyone,

I have been a long time AutoIT user, but this is actually the first time I post a message in these forums.

Up to now I was always able to get things to work, but this issue seems to be a bit more complex. 

I have two webpages for which the second one is called from the first one. The first web page contains two fields, a text field and a drop down box. The robot keys in the value "a" in the text field and select the value "b" in the drop down box. For simplicity these things are hard coded in this code sniplet. Once pressing the submit button, the second web page is loaded which also has a text field and a drop down box.

I have added some message boxes in this second block and once executed I figured out that the $o_IE1 is actually the same object as in the first page. Once in the loop I see the fields from the first web page.

Anyway, so it looks the $o_IE1 is not a new object. I tried to force things, by using WinActivate and _IEAttach, but this does not fully make everything work. Without those two I cannot see the form from the second page at all.

Can somebody give me some directions please ?

Warm regards

; Add include file in program...
#include "IE.au3"

_IEErrorHandlerRegister()

; Initialize IE browser object...
$o_IE = _IECreate("about:blank", 0, 1, 1, 1)
$hGUI = WinGetHandle("[Class:IEFrame]")

; Initialize variables...
$URLData = "<Internal URL>"

; Load URL in browser...
_IENavigate ($o_IE, $URLData, "NoWait")

;;;;
; Page 1
;;;;

; Get Browser form details...
$oForm = _IEFormGetCollection($o_IE, 0)
$oFormFields = _IEFormElementGetCollection($oForm)

; Find field name in HTML form...
For $oFormField in $oFormFields

   If $oFormField.type = "text" Then
      _IEFormElementSetValue($oFormField, "a")

   ElseIf $oFormField.type = "select-one" Then
      _IEFormElementOptionSelect($oFormField, "b", 1 , "byText", 1)
   EndIf

Next

_IEFormSubmit($oForm, 0) ;<< until here everything works normal

;;;;
; Page 2
;;;;
WinActivate($hGUI)
$o_IE1 = _IEAttach($hGUI, "hwnd")

; Get Browser form details...
;$oForm1 = _IEFormGetCollection($o_IE1, 0)
;$oFormFields1 = _IEFormElementGetCollection($oForm1)

; Find field name in HTML form...
For $oFormField in _IEFormElementGetCollection($oForm)

   If $oFormField.type = "text" Then
      _IEFormElementSetValue($oFormField, "c")


   ElseIf $oFormField.type = "select-one" Then
      _IEFormElementOptionSelect($oFormField, "d", 1 , "byText", 1)
   EndIf

Next

_IEFormSubmit($oForm, 0)

 

Edited by MeAgain

Share this post


Link to post
Share on other sites



_IENavigate ($o_IE, $URLData, "NoWait")

"NoWait" is not a valid parameter. This should be either a 0 or  a 1.

Beyond that, it's difficult to know where the issue resides with the limited details provided.

Share this post


Link to post
Share on other sites

It's me again,

Thanks for that, I have removed the NoWait, since it is an optional parameter I believe.

Not sure why you say I have provided limited details, though.

I was hoping this is a 'known' issue in the community, although I could not find a lot about it in the forums.

By the way my desktop is a Windows 7 machine and it is IE11. This script used to work on a Windows XP machine before, but this was about a year ago.

 

Share this post


Link to post
Share on other sites

The limited details is because of the super secret url.

One of the most time consuming  things to solve your problem from the perspective of others, is finding an accessible website where the same problem occurs. That task should be up to you, since you are the one needing help.

it is impossible to know how your confidential URL works, so it is in your best interest to provide people who might possibly solve your issue, with a means of testing it via a reproducer they can actually try.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

What AutoIt version?

3 hours ago, MeAgain said:

Not sure why you say I have provided limited details, though.

You haven't provided enough information to allow someone to duplicate the issue. It appears that you are accessing an internal site, so I understand that we can't test on the actual site. Have you tried to identify another publicly accessible site that could be used to demonstrate the issue?

Also, you haven't shown us any of the underlying HTML code. My crystal ball is in the shop, so I'm unable to predict what is actually occurring with your unique situation. ;-)

Share this post


Link to post
Share on other sites

Ok, I understand, sorry for that.

Please find attached all the files required to test this issue.

I have now also tried it on my desktop at home, which is also a Windows 7 with IE11 machine, and there I have the same issue.

Thanks in advance for helping me.

Test robot.au3

test1.html

test2.html

test3.html

Share this post


Link to post
Share on other sites

Some more info, I have just installed AutoIT on my desktop at home, so that will be version 3.3.14.0.

Share this post


Link to post
Share on other sites

Here's a revised script that works for me:

#include "IE.au3"

$o_IE = _IECreate(@ScriptDir & '\test1.html')

;;;;
; Page 1
;;;;

$oForm = _IEFormGetCollection($o_IE, 0)
$oField = _IEFormElementGetObjByName($oForm, "FieldA")
_IEFormElementSetValue($oField, "A")

$oSelect =  _IEFormElementGetObjByName($oForm, "FieldB")
_IEFormElementOptionSelect($oSelect,  "b", 1 , "byText", 1)

Sleep(2000)

_IEFormSubmit($oForm)

;;;;
; Page 2
;;;;

$oForm = _IEFormGetCollection($o_IE, 0)
$oField = _IEFormElementGetObjByName($oForm, "FieldC")
_IEFormElementSetValue($oField, "C")

$oSelect =  _IEFormElementGetObjByName($oForm, "FieldD")
_IEFormElementOptionSelect($oSelect,  "d", 1 , "byText", 1)

Sleep(2000)

_IEFormSubmit($oForm)

The Sleep statements are only there to allow the user to see that the fields were correctly updated. ;-)

Share this post


Link to post
Share on other sites

Thanks a lot Danp2 for your script.

With your script I have the exact same symptons as with my original script. It does not find the fields on the second page and thus they are not populated.

Which OS do you have and which version of IE ?

Share this post


Link to post
Share on other sites

Windows 10 x64

IE 11

Share this post


Link to post
Share on other sites
13 hours ago, MeAgain said:

Thanks in advance for helping me.

Test robot.au3

test1.html

test2.html

test3.html

I change this:

; Initialize variables...
$URLData = @ScriptDir & "\test1.html"

 

you should to use:

#include <IE.au3>
; instead
; #include "IE.au3"

unless you have your own modified version of this UDF.


Question:
What happend to IE when you submit 

  • open new separate IE window
  • open new Tab in current IE window
  • open new document in current Tab of current IE 

?

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Ok, thanks for pointing that out. I fixed the include statement in the script, but still suffering the issue.

When the robot clicks submit, it loads test2.html in the same tab, in the same IE window.

Share this post


Link to post
Share on other sites

 

1 hour ago, MeAgain said:

When the robot clicks submit, it loads test2.html in the same tab, in the same IE window.

 

On 11.02.2016 at 7:38 PM, MeAgain said:

I have added some message boxes in this second block and once executed I figured out that the $o_IE1 is actually the same object as in the first page. Once in the loop I see the fields from the first web page.

Anyway, so it looks the $o_IE1 is not a new object.

This is correct, behavior in this case, as you have still the same Instance of IE object.

 

So with this knowledge, what you want to achieve now ?

 

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

I want the robot to be able fill in the fields on the second page.

How do I refresh the $o_IE object, so it contains the fields in the second form ?

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Me again.

I just double checked this script below on a Windows XP IE8, where it works as expected.

It does not work on Windows 7 IE11, on two machines.

#include <IE.au3>

; Initialize IE browser object...
$o_IE = _IECreate("about:blank", 0, 1, 1, 1)

; Initialize variables...
$URLData = "http://192.168.1.2/test1.html"

; Load URL in browser...
_IENavigate($o_IE, $URLData)

;;;;
; Page 1
;;;;
$oForm = _IEFormGetCollection($o_IE, 0)
$oField = _IEFormElementGetObjByName($oForm, "FieldA")
_IEFormElementSetValue($oField, "A")

$oSelect =  _IEFormElementGetObjByName($oForm, "FieldB")
_IEFormElementOptionSelect($oSelect,  "b", 1 , "byText", 1)

_IEFormSubmit($oForm)

;;;;
; Page 2
;;;;
$oForm = _IEFormGetCollection($o_IE, 0)
$oField = _IEFormElementGetObjByName($oForm, "FieldC")

_IEFormElementSetValue($oField, "C")

$oSelect =  _IEFormElementGetObjByName($oForm, "FieldD")
_IEFormElementOptionSelect($oSelect,  "d", 1 , "byText", 1)

_IEFormSubmit($oForm)

 

Edited by MeAgain

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

Nobody can come with a solution, so it is moved to the General Help and Support section, right ?

This simple code is not working on Windows 7 IE11 and I tried it on two different PCs !

Are you kidding me ?

Edited by MeAgain

Share this post


Link to post
Share on other sites

There was an update from MS around 18 months ago that caused havoc with IE automation. Perhaps that affecting your script. <shrug>

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

17 minutes ago, Danp2 said:

There was an update from MS around 18 months ago that caused havoc with IE automation. Perhaps that affecting your script. <shrug>

Was not it already been fixed ? Unless we are talking about the same problem.

 


@MeAgain

1.

Open second page. Attach to them.

and check @extended 

Local $oFrames = _IEFrameGetCollection($oIE)
MsgBox(0, 'Frame count', @extended)

 

2.

What your script doing beetwen this two functions:

_IEFormSubmit($oForm)

;;;;
; Page 2
;;;;
$oForm = _IEFormGetCollection($o_IE, 0)

 

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

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