Jump to content

Object lost at second web page


MeAgain
 Share

Recommended Posts

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
Link to comment
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.

 

Link to comment
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.

Link to comment
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. ;-)

Link to comment
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. ;-)

Link to comment
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 ?

Link to comment
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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...