Jump to content

_IE script won't work unless IE is already open from previous run


Recommended Posts

Hi all,

I've got a strange issue where if I run my script with IE closed (Or open not on page requested) then my script fails with the below. However if after running once, the IE window is open on the page requested then it runs fine!

--> IE.au3 T3.0-1 Warning from function _IEAttach, $_IEStatus_NoMatch
--> IE.au3 T3.0-1 Error from function _IELoadWait, $_IEStatus_ClientDisconnected (-2147417848, Browser has been deleted prior to operation.)
--> IE.au3 T3.0-1 Error from function _IEFrameGetObjByName, $_IEStatus_InvalidObjectType
--> IE.au3 T3.0-1 Error from function _IEFormGetObjByName, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEGetObjByName, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEGetObjByName, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEGetObjByName, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEFormElementSetValue, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEFormElementCheckBoxSelect, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEFormSubmit, $_IEStatus_InvalidDataType
--> IE.au3 T3.0-1 Error from function _IEQuit, $_IEStatus_InvalidObjectType

Code:

$IE = _IECreate($URL,1,1,1,1) ;Open OR-WFMT
Sleep(1000)

If @error<>0 Then
    ConsoleWriteError("Error creating webpage: "&@error)
    Exit
EndIf

;Get the username,password & checkbox fields for login
Local $IEFram       = _IEFrameGetObjByName($IE, $loginFrameName)
Local $loginForm    = _IEFormGetObjByName($IEFram, $loginFormName)
Local $loginUserEntry   = _IEGetObjByName($loginForm, $loginUsernameFieldName)
Local $loginPassEntry   = _IEGetObjByName($loginForm, $loginPasswordFieldName)
Local $loginCBoxEntry   = _IEGetObjByName($loginForm, $loginCheckBoxFieldName)

;set the login information
_IEFormElementSetValue($loginUserEntry, $username)
_IEFormElementSetValue($loginPassEntry, $password)
_IEFormElementCheckBoxSelect($loginForm, $loginCheckBoxFieldName, $loginCheckBoxFieldName, 1, 0, 0)

;executes login
_IEFormSubmit($loginForm, 0)
If @error<>0 Then
    ;MsgBox(1, "Error", "Failed to login to OR-WFMT")
    ConsoleWriteError("Failed to login to OR-WFMT with error code: "&@error)
    _IEQuit($IE)
    Exit
EndIf

I can't run the script twice/have IE already open in live.

I've been racking my head about this all day and cannot think for the life of me why this is! (My first thought being _IECreate is not returning a valid object type?).

Any help would be greatly appreciated!

Thanks,

Alex

Link to comment
Share on other sites

change this:

$IE = _IECreate($URL,1,1,1,1) ;Open OR-WFMT
Sleep(1000)

If @error<>0 Then
    ConsoleWriteError("Error creating webpage: "&@error)
    Exit
EndIf

to this:

$IE = _IECreate($sURL, 1, 1, 1, 1) ;Open OR-WFMT
Local $error = @error
Local $extended = @extended
ConsoleWrite("@error creating webpage: " & $error & @CRLF)
ConsoleWrite("@extended creating webpage: " & $extended & @CRLF)


If $error <> 0 Then
    ConsoleWriteError("Error creating webpage: " & @error)
    Exit
EndIf

and give back console output.

ps.

Welcome to the forum

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

Hi mLipok, cheers :)

After adding @extended in, the console output provides the following;

--> IE.au3 T3.0-1 Warning from function _IEAttach, $_IEStatus_NoMatch
--> IE.au3 T3.0-1 Error from function _IELoadWait, $_IEStatus_ClientDisconnected (-2147417848, Browser has been deleted prior to operation.)
@error creating webpage: 9
@extended creating webpage: 0
--> IE.au3 T3.0-1 Error from function _IEFrameGetObjByName, $_IEStatus_InvalidObjectType
....
--> IE.au3 T3.0-1 Error from function _IEQuit, $_IEStatus_InvalidObjectType

Not sure why I'm getting client disconnected errors when this is the first instance of IE.

I did find a workaround but am not really satisfied;

Local $tempIE = _IECreate($URL,1,1,1,1) ;
Sleep(1000)
$IE = _IECreate($URL,1,1,1,1) ;

Effectively opens the page in two instances.

The output of this actually ends in only one tab being opened in IE, when $IE is created it just refreshes the page.

Link to comment
Share on other sites

when you use _IECreate only once , did you get this $URL opened in IE and only @error = 9
or
IE do not open $URL ?
 


try this:

$IE = _IECreate() ;Open OR-WFMT
$IE = _IECreate($sURL, 1, 1, 1, 0) ;Open OR-WFMT
Local $error = @error
Local $extended = @extended
ConsoleWrite("@error creating webpage: " & $error & @CRLF)
ConsoleWrite("@extended creating webpage: " & $extended & @CRLF)
_IELoadWait($IE,500)

If $error <> 0 Then
    ConsoleWriteError("Error creating webpage: " & @error)
    Exit
EndIf

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

Yeah if I only use _IECreate once IE opens at the desired URL, then throws the errors.

I tried using  a blank _IECreate() followed by the correct _IECreate($URL,1,1,1,1). This results in 2 separate IE windows being opened  and the same errors being thrown.

I'll get my colleague to try on his machine and see if we can duplicate the error.

 

Link to comment
Share on other sites

so I be waiting for further information

Cheers

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

Just tried the same on a colleagues computer. 

Running the script gets the same errors.

Running the script with workaround does not work & gets same errors.

Running the script with workaround compiled does work.

Strange :/

JohnOne, Just tried with google.com and it works fine.

The site I'm trying to access is an internal site; JSF based with javascript & uses ajax for the frames I'm accessing.

I've tried using sleep(10000) to allow plenty of time for all ajax elements to load (they generally load before the page has rendered anyway)

I can't really understand why this happens for my URL but not for google.

Link to comment
Share on other sites

My guess would be that the page you are opening is running in a different security zone. This creates a new browser instance and the one returned by _IECreate is invalid.

You could play with configuring security zones or if it works if the window is already up, try using _IEAttach after the IECreate.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

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...