Jump to content
Sign in to follow this  
lovett1991

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

Recommended Posts

lovett1991

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

Share this post


Link to post
Share on other sites
mLipok

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
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 APIErrorLog.au3 UDF - A logging Library
 

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 *

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 * 

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 TaskScheduler

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: 2018-10-31

Share this post


Link to post
Share on other sites
lovett1991

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.

Share this post


Link to post
Share on other sites
mLipok

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:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
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 APIErrorLog.au3 UDF - A logging Library
 

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 *

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 * 

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 TaskScheduler

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: 2018-10-31

Share this post


Link to post
Share on other sites
lovett1991

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.

 

Share this post


Link to post
Share on other sites
mLipok

so I be waiting for further information

Cheers

mLipok


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
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 APIErrorLog.au3 UDF - A logging Library
 

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 *

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 * 

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 TaskScheduler

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: 2018-10-31

Share this post


Link to post
Share on other sites
lovett1991

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.

Share this post


Link to post
Share on other sites
DaleHohm

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

Share this post


Link to post
Share on other sites
lovett1991

Yes the site is within the Intranet zone.

It appears that any site greenside throws the same errors. 

I cannot change any IE related settings as I'm using the environment settings.

Is there a way around this?

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  

×