Handle to IE lost with IE 11 on windows 8.1

Started by hdsouza, April 11, 2014, 05:54:39 AM

Previous topic - Next topic

hdsouza

If a timedelay precedes the wait_for_msie check and the page has transitioned to another page then winbatch losses the handle to IE
What really happens is msie.busy continues to return a -1 even after the page is loaded
This happens on Windows 8.1 - IE11 -  Winbatch 2014A
UAC has been disabled on windows 8.1, so that should not be the problem

The exact same code works fine on:
Windows 7 - IE 8 - Winbatch 2010A
Windows XP - IE 8 - Winbatch 2010A

Code (winbatch) Select


FileDelete("c:\temp\applog.txt")
DebugTrace(@on,"c:\temp\applog.txt")
EODData_Login =  "ezmail1968@gmail.com"
EODData_Password = "password"

msie = ObjectOpen("InternetExplorer.Application")
;msie = ObjectCreate("InternetExplorer.Application")
msie.Visible = @True
msie.Navigate("http://eoddata.com/")
GoSub WaitForMSIE
msie.document.GetElementByid("ctl00_cph1_lg1_txtEmail").value = EODData_Login
msie.document.GetElementByid("ctl00_cph1_lg1_txtPassword").value = EODData_Password
msie.document.GetElementByid("ctl00_cph1_lg1_btnLogin").click
GoSub WaitForMSIE
msie.Navigate("http://eoddata.com/download.aspx")
exit

:WaitForMSIE
Timedelay(1)
aa = msie.busy
while msie.busy
    aa = msie.busy
    timedelay(1)
endwhile
Return



Deana

I see you are trying to use the Click() method which will fail on IE 9 and newer. This is due to security changes in IE.  The workaround I have found is to use a dispatchEvent:

Code (winbatch) Select
; Click button
;oElement.Click             
;or
; Click button on IE 9 and newer
; createEvent initEvent DispatchEvent
oEvent = oIE.Document.createEvent("HTMLEvents")
oEvent.initEvent("click", @TRUE, @TRUE)
oElement.dispatchEvent(oEvent)
oEvent = 0



Use the above code to click the submit button on the login page. I already posted a code sample for you in your other thread on this topic. here is a link to that topic: http://forum.winbatch.com/index.php?topic=872.msg3549#msg3549


Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

I am able to click the button using the earlier program.
In any case I used the dispatchEvent code you provided although it fails on line oEvent.initEvent("click", @TRUE, @TRUE)
TERMINAL WIL ERROR=>3131 (OleExecute: Not a valid OLE object. Period may have been used in place of a comma.)

Code (winbatch) Select

FileDelete("c:\temp\applog.txt")
DebugTrace(@on,"c:\temp\applog.txt")
EODData_Login =  "ezmail1968@gmail.com"
EODData_Password = "password"


msie = ObjectOpen("InternetExplorer.Application")
;msie = ObjectCreate("InternetExplorer.Application")
msie.Visible = @True
msie.Navigate("http://eoddata.com/")
GoSub WaitForMSIE
msie.document.GetElementByid("ctl00_cph1_lg1_txtEmail").value = EODData_Login
msie.document.GetElementByid("ctl00_cph1_lg1_txtPassword").value = EODData_Password
;msie.document.GetElementByid("ctl00_cph1_lg1_btnLogin").click
oElement = msie.document.GetElementByid("ctl00_cph1_lg1_btnLogin")
oEvent = msie.document.createEvent("HTMLEvents")
oEvent.initEvent("click", @TRUE, @TRUE)
oElement.dispatchEvent(oEvent)
oEvent = 0

GoSub WaitForMSIE
msie.Navigate("http://eoddata.com/download.aspx")
exit

:WaitForMSIE
Timedelay(1)
aa = msie.busy
while msie.busy
    aa = msie.busy
    timedelay(1)
endwhile
Return


Deana

Again IE 9 and newer have quite a bit more built in security. The code you posted from before called click() but then immediately called Navigate() which made it APPEAR as though your click is working.

Looks like you will need to avoid using the .navigate method otherwise you will loose all of the _Viewstate data required by the site. The navigate causes a logout.

Once you login, is there a link on the page that takes you to the download page? You can get a list of links using something like this:

Code (winbatch) Select
;LinksCollection = oIE.document.links
list = ''
ForEach link In LinksCollection
   Link_Href = strtrim(link.href)
   if list == '' then list = Link_Href
   else list = list:@tab:Link_Href
Next
AskItemList('', list, @tab, @unsorted, @single )


As for the error, I just tested the code on Windows 7 with IE 11 and it works for me. I recommend using DebugTrace(@on,"trace.txt"). Add it to the beginning of the script, run it until the error, then inspect the resulting trace file for clues as to the problem

Feel free to post the trace file here ( removing any private info) if you need further assistance.
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

Here is a code sample I came up with the avoids using the Navigate method:

Code (winbatch) Select

;***************************************************************************
;**                  EODDATA Auto-Login and download
;**      Logs into your EODDATA account online and attempts to download data.
;**
;**       Ensure that you are signed-out of EODDATA before running!
;**
;** Developer: Deana Falk 2014.04.11                 
;***************************************************************************

;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; Ensure that you are signed-out of EODDATA before running
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#DefineFunction udfIEPageLoadWait( objIE )
    ; Wait for webpage to load
    While !(objIE.readyState == 'complete' || objIE.readyState == 4 )
       TimeDelay(0.1)
    EndWhile
    While !(objIE.document.readyState == 'complete' || objIE.document.readyState == 4 )
       TimeDelay(0.1)
    EndWhile
    Return 1
#EndFunction

url = 'http://www.eoddata.com'

EODData_Login =  "soandso@blahblah.com" ; MODIFY TO FIT YOUR NEEDS
EODData_Password = "******" ; MODIFY TO FIT YOUR NEEDS

oIE = ObjectCreate('internetexplorer.application')
oIE.visible = @true;
oIE.navigate(url);

udfIEPageLoadWait( oIE )

; Wait for First element ( helps with timing )
While @true
   oElement = oIE.Document.getElementById("ctl00_cph1_lg1_txtEmail")
   type = ObjectTypeGet(oElement)
   if type != 'NULL' then break
EndWhile
oElement.value = EODData_Login

oElement = oIE.Document.getElementById("ctl00_cph1_lg1_txtPassword")
oElement.value = EODData_Password

; Click button
oElement = oIE.Document.getElementById("ctl00_cph1_lg1_btnLogin")
;oElement.Click             
;or
; Click button on IE 9 and newer
; createEvent initEvent DispatchEvent
oEvent = oIE.Document.createEvent("HTMLEvents")
oEvent.initEvent("click", @TRUE, @TRUE)
oElement.dispatchEvent(oEvent)

oEvent = 0
oElement = 0

udfIEPageLoadWait( oIE )

; Click link to go to download section
; Use Click link method in stead of Navigate() because Navigates losses __ViewState logginn info
LinksCollection = oIE.document.links
ForEach link In LinksCollection
   Link_Href = strtrim(link.href)
   Link_Exist =  StrIndexNC(Link_Href, "download.aspx", 1, @FWDSCAN);!!!!!!!
   if Link_Exist == 0 then Continue
   ; Click link
   oEvent = oIE.Document.createEvent("HTMLEvents")
   oEvent.initEvent("click", @TRUE, @TRUE)
   link.dispatchEvent(oEvent)
Next

udfIEPageLoadWait( oIE )

; Select Downlad Details
While @true
   oElement = oIE.document.getElementsByTagName("select")
   type = ObjectTypeGet(oElement)
   if type != 'NULL' then break
   TimeDelay(0.25)
EndWhile
oExchange = oElement.Item(0) ; select the exchange
Select_ExchangePos = 20 ; Nasdaq
oExchange.Options.Item(Select_ExchangePos).selected = @TRUE ; set the exchange
oFormat= oIE.document.getElementsByTagName("select").item(1) ; Set the format
Select_FormatPos = 1
oFormat.Options.item(Select_FormatPos).selected = @TRUE
oIE.document.GetElementByid("ctl00_cph1_d1_chkAllSymbols").checked = 1
oIE.document.GetElementByid("ctl00_cph1_d1_chkAllSymbols").fireevent("onclick")

; Wait for Download button element element
While @true
   oElement = oIE.Document.getElementById("ctl00_cph1_d1_btnDownload")
   type = ObjectTypeGet(oElement)
   if type != 'NULL' then break
EndWhile
; Click Download button element element
oEvent = oIE.Document.createEvent("HTMLEvents")
oEvent.initEvent("click", @TRUE, @TRUE)
oElement.dispatchEvent(oEvent)

Timedelay(10)
SendKey( '{TAB 2}' )
SendKey( '{DOWN 2}' )
SendKey( '{ENTER}' )

oEvent = 0
oElement = 0
oSelect_Format = 0
oExchange = 0
oIE = 0
Exit
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

I am not disputing what you are saying about the security changes, but from what I am seeing is that the click works because I can see that the webpage has logged in. remember I have "msie.Visible = @True" in the code. Also I have additional code to confirm that the page has logged in but has removed from this script for easier understanding and avoid the clutter. Also navigate does cause the page to logout. Same reason as earlier .. I can see it on screen.

All I am saying is that in Windows 8.1 with IE 11 MSIE.BUSY throws out a -1 even after the page is loaded after its gone through one transition.  If you run my first script as-is you will see the problem immediately.. again on 8.1 with IE 11. If you replace the timedelay(1)  which is located at the start of the waitformsie loop  with Display (1, "WaitForMsie Delay loop", "1 sec delay") the problem goes away. If this is true which appears to be at least from what I am seeing then there could be other issues with the way winbatch is handling IE. Maybe something to be investigated

As for the second code .. the one modified with the dispatch here is the debug if its still needed

Deana

Please try running the code I took the time to write and let me know if it works for you.
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

Deana, I have run the code you gave me . It fails on the same line as mentioned earlier
oEvent.initEvent("click", @TRUE, @TRUE)
TERMINAL WIL ERROR=>3131 (OleExecute: Not a valid OLE object. Period may have been used in place of a comma.)

The debug output was attached to my earlier post. Attached it here again if you need it

Deana

Quote from: hdsouza on April 11, 2014, 09:52:56 AM
All I am saying is that in Windows 8.1 with IE 11 MSIE.BUSY throws out a -1 even after the page is loaded after its gone through one transition.  If you run my first script as-is you will see the problem immediately.. again on 8.1 with IE 11. If you replace the timedelay(1)  which is located at the start of the waitformsie loop  with Display (1, "WaitForMsie Delay loop", "1 sec delay") the problem goes away. If this is true which appears to be at least from what I am seeing then there could be other issues with the way winbatch is handling IE. Maybe something to be investigated

In the attached code I included a UDF to wait for the page to load and it checks more than just the IE Busy property. Give that code a try.
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

Quote from: hdsouza on April 11, 2014, 10:28:59 AM
Deana, I have run the code you gave me . It fails on the same line as mentioned earlier
oEvent.initEvent("click", @TRUE, @TRUE)
TERMINAL WIL ERROR=>3131 (OleExecute: Not a valid OLE object. Period may have been used in place of a comma.)

The debug output was attached to my earlier post. Attached it here again if you need it

Based on the trace file I see the CreateEvent is returning nothing...not sure why at this point.
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

I already did. it fails on the line above. I look at the attached debug you will see its your code that i executed

Deana

Quote from: hdsouza on April 11, 2014, 10:37:07 AM
I already did. it fails on the line above. I look at the attached debug you will see its your code that i executed

Give this a try:

Code (winbatch) Select
oElement.fireevent("onclick")


Here is a revised script to try:
Code (winbatch) Select

;***************************************************************************
;**                  EODDATA Auto-Login and download
;**      Logs into your EODDATA account online and attempts to download data.
;**
;**       Ensure that you are signed-out of EODDATA before running!
;**
;** Developer: Deana Falk 2014.04.11                 
;***************************************************************************

;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; Ensure that you are signed-out of EODDATA before running
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

#DefineFunction udfIEPageLoadWait( objIE )
    ; Wait for webpage to load
    While !(objIE.readyState == 'complete' || objIE.readyState == 4 )
       TimeDelay(0.1)
    EndWhile
    While !(objIE.document.readyState == 'complete' || objIE.document.readyState == 4 )
       TimeDelay(0.1)
    EndWhile
    Return 1
#EndFunction

#DefineFunction udfClick(oIE, oElement)
   ; Used Click button on IE 9 and newer
   oEvent = oIE.Document.createEvent("HTMLEvents") 
   if oEvent
      oEvent.initEvent("click", @TRUE, @TRUE)
      oElement.dispatchEvent(oEvent)
   else
      oElement.fireEvent("onclick")
   Endif
#EndFunction

url = 'http://www.eoddata.com'

EODData_Login =  "soandso@blahblah.com" ; MODIFY TO FIT YOUR NEEDS
EODData_Password = "****" ; MODIFY TO FIT YOUR NEEDS

oIE = ObjectCreate('internetexplorer.application')
oIE.visible = @true;
oIE.navigate(url);

udfIEPageLoadWait( oIE )

; Wait for First element ( helps with timing )
While @true
   oElement = oIE.Document.getElementById("ctl00_cph1_lg1_txtEmail")
   type = ObjectTypeGet(oElement)
   if type != 'NULL' then break
EndWhile
oElement.value = EODData_Login

oElement = oIE.Document.getElementById("ctl00_cph1_lg1_txtPassword")
oElement.value = EODData_Password

; Click button
oElement = oIE.Document.getElementById("ctl00_cph1_lg1_btnLogin")
;oElement.Click             
;or
; Click button on IE 9 and newer
; createEvent initEvent DispatchEvent
;oEvent = oIE.Document.createEvent("HTMLEvents")
;oEvent.initEvent("click", @TRUE, @TRUE)
;oElement.dispatchEvent(oEvent)
udfClick(oIE, oElement)
oEvent = 0
oElement = 0

udfIEPageLoadWait( oIE )

; Click link to go to download section
; Use Click link method in stead of Navigate() because Navigates losses __ViewState logginn info
LinksCollection = oIE.document.links
ForEach link In LinksCollection
   Link_Href = strtrim(link.href)
   Link_Exist =  StrIndexNC(Link_Href, "download.aspx", 1, @FWDSCAN);!!!!!!!
   if Link_Exist == 0 then Continue
   ; Click link
   udfClick(oIE, link) 
Next

udfIEPageLoadWait( oIE )

; Select Downlad Details
While @true
   oElement = oIE.document.getElementsByTagName("select")
   type = ObjectTypeGet(oElement)
   if type != 'NULL' then break
   TimeDelay(0.25)
EndWhile
oExchange = oElement.Item(0) ; select the exchange
Select_ExchangePos = 20 ; Nasdaq
oExchange.Options.Item(Select_ExchangePos).selected = @TRUE ; set the exchange
oFormat= oIE.document.getElementsByTagName("select").item(1) ; Set the format
Select_FormatPos = 1
oFormat.Options.item(Select_FormatPos).selected = @TRUE
oIE.document.GetElementByid("ctl00_cph1_d1_chkAllSymbols").checked = 1
oIE.document.GetElementByid("ctl00_cph1_d1_chkAllSymbols").fireevent("onclick")

; Wait for Download button element element
While @true
   oElement = oIE.Document.getElementById("ctl00_cph1_d1_btnDownload")
   type = ObjectTypeGet(oElement)
   if type != 'NULL' then break
EndWhile
; Click Download button element element
udfClick(oIE, oElement)

TimeDelay(3)

SendKey( '{TAB 2}' )
SendKey( '{DOWN 2}' )
SendKey( '{ENTER}' )

oEvent = 0
oElement = 0
oSelect_Format = 0
oExchange = 0
oIE = 0
Exit

Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

this code gives me a diferent error. It fails in the udfclick function.
I believe we are trying to solve a problem which does not exist. If you read my first and third reply on this post the problem is not with clicking or navigating when I use my scripts.  The problem lies in msie.busy and only during a particular instance. Again see my 1st and 3rd reply on this post. I also had a workaround mentioned there.
I was merely mentionning a limitation in winbatch when used with WIN 8.1 and ie 11 and others could have the same problems. So this is something you may want to report to the coders. Again please see my first and third replies

Deana

Quote from: hdsouza on April 11, 2014, 11:39:24 AM
this code gives me a diferent error. It fails in the udfclick function.
I believe we are trying to solve a problem which does not exist. If you read my first and third reply on this post the problem is not with clicking or navigating when I use my scripts.  The problem lies in msie.busy and only during a particular instance. Again see my 1st and 3rd reply on this post. I also had a workaround mentioned there.
I was merely mentionning a limitation in winbatch when used with WIN 8.1 and ie 11 and others could have the same problems. So this is something you may want to report to the coders. Again please see my first and third replies

I think the TimeDelay is a "red herring". I currently think the issue caused by using the Navigate method. Simply modify the code you posted in post 1 to use the link click method instead of Navigate.  Can you confirm? 

Also I recommend check more than just the busy property when waiting for a webpage to load. Maybe use the ReadyState property too.
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

The navigate is not the problem. The problem occours before the second navigate. it gets stuck in the waitformise loop. Did you try running it yourself and seeing the problem.

Deana

Quote from: hdsouza on April 11, 2014, 12:50:12 PM
The navigate is not the problem. The problem occours before the second navigate. it gets stuck in the waitformise loop. Did you try running it yourself and seeing the problem.
Yes I did run your code and it runs fine on my system.
Deana F.
Technical Support
Wilson WindowWare Inc.

hdsouza

What are the OS and browser versions of your machine?

Deana

Quote from: hdsouza on April 11, 2014, 01:01:03 PM
What are the OS and browser versions of your machine?
As previously stated Windows 7 and IE11.
Deana F.
Technical Support
Wilson WindowWare Inc.

Deana

I also just tested your code on Windows 8.1 with IE 11 and it worked.
Deana F.
Technical Support
Wilson WindowWare Inc.

td

Just a side note.   The OP mentioned that UAC was disabled on Window 8.1.  UAC is never disabled on Windows 8.1.  Windows 8.1 only allows you to disable the elevation prompt which is not synonymous with UAC being disabled.   If you are a relatively sophisticated  user of Windows 8.1 , the difference between disabling the prompt and really disabling UAC will become apparent over time.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

hdsouza

Quote from: td on April 11, 2014, 01:46:44 PM
Just a side note.   The OP mentioned that UAC was disabled on Window 8.1.  UAC is never disabled on Windows 8.1.  Windows 8.1 only allows you to disable the elevation prompt which is not synonymous with UAC being disabled.   If you are a relatively sophisticated  user of Windows 8.1 , the difference between disabling the prompt and really disabling UAC will become apparent over time.
TD I am sure you are extremely sofisticated with windows 8.1 and also with winbtach. So if you are can you provide us a solution to the problem. Also I have been doing winbatch for over 10 years now, posted several times on the forum for help and helped others too, but have never once been called unsophisticated or called others unsofisticated

td

Quote from: hdsouza on April 11, 2014, 02:34:37 PM
TD I am sure you are extremely sofisticated with windows 8.1 and also with winbtach. So if you are can you provide us a solution to the problem. Also I have been doing winbatch for over 10 years now, posted several times on the forum for help and helped others too, but have never once been called unsophisticated or called others unsofisticated

I am sorry you took it personally but that was not the intention.  The point is that you cannot turn off UAC on Windows 8.x and this fact is of importance when using WinBatch.  This is not apparent to users that don't regularly attempt to do things like write complex automation scripts or develop and debug native applications. However, if you do happen to do these things, the fact that almost all processes are running with a restricted admin token and only medium integrity even when UAC prompting is off will eventually but probably not immediately become apparent.

The reason that this of importance to WinBatch users is that by default the WinBatch process runs with a full admin token and high integrity. But since most other admin processes are running with a restricted token and medium integrity,Windows will bock some interactions between WinBatch and other processes. The net effect can be some very difficult to diagnose problems in your WinBatch scripts unless you understand that UAC is on even when you turn prompting off.     

With regard to your Web automation problem, Deana has the expertise in that area.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade