Problems with IE11 Click Automation

Started by apeacock, April 22, 2015, 12:06:20 PM

Previous topic - Next topic

apeacock

I have a WinBatch script that I'm trying to move from IE8 to IE11 (using WinBatch+Compiler 2012A).  It includes a click on a button defined as follows:

   <td>
      <input name="ign_choose" type="submit" value="Receive">
      <input name="use_gross" type="hidden" value="0">
      <input name="packageid" type="hidden" value="333333">
      <input name="lotno_prefix" type="hidden" value="M333333X">
      <input name="use_seqno" type="hidden" value="1">
   </td>

The original code gets the element object then used click.  That approach works, but the WinBatch script then hangs.  I can step through the script and complete the click line, but then script won't allow me to step forward any longer once the next page loads.  I have to use Ctrl+Break and stop the script at that point.

I've tried using some the newer click approach listed in some of the other posts:
   ... (msie1 is my IE object)
   msie1Element = msie1.document.getElementsByName("ign_choose").item(0)
   checkval = msie1Element.value  ;watch shows "Receive", as expected
   msie1Event = msie1.document.createEvent("HTMLEvents")
   msie1Event.initEvent("click", @TRUE, @TRUE)
   msie1Element.dispatchEvent(msie1Event)
   msie1Event = 0
   msie1Element = 0
However, this doesn't work (nothing happens in the browser).

Any suggestions on how to click the button without hanging the script?

Thanks!

td

Quote from: apeacock on April 22, 2015, 12:06:20 PM
I have a WinBatch script that I'm trying to move from IE8 to IE11 (using WinBatch+Compiler 2012A).  It includes a click on a button defined as follows:

   <td>
      <input name="ign_choose" type="submit" value="Receive">
      <input name="use_gross" type="hidden" value="0">
      <input name="packageid" type="hidden" value="333333">
      <input name="lotno_prefix" type="hidden" value="M333333X">
      <input name="use_seqno" type="hidden" value="1">
   </td>

The original code gets the element object then used click.  That approach works, but the WinBatch script then hangs.  I can step through the script and complete the click line, but then script won't allow me to step forward any longer once the next page loads.  I have to use Ctrl+Break and stop the script at that point.

I've tried using some the newer click approach listed in some of the other posts:
   ... (msie1 is my IE object)
   msie1Element = msie1.document.getElementsByName("ign_choose").item(0)
   checkval = msie1Element.value  ;watch shows "Receive", as expected
   msie1Event = msie1.document.createEvent("HTMLEvents")
   msie1Event.initEvent("click", @TRUE, @TRUE)
   msie1Element.dispatchEvent(msie1Event)
   msie1Event = 0
   msie1Element = 0
However, this doesn't work (nothing happens in the browser).

Any suggestions on how to click the button without hanging the script?

Thanks!

Another twist on  the IE-whatever-to-IE11-script-doesn't-work-now problem.    If I recall correctly, the click method will fail when using IE 11 objects unless you have set the page to be viewed in Compatibility View but I don't recall this problem ever causing the Click method to hang. 

Other than checking to make sure you are sending the event to the correct element, I don't see anything inherently wrong with your attempt at using the newer approach either.  Perhaps one of our IE11 browser object savvy forum members has an explanation.  I will check around a bit to see if I can gain any additional insights. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

I do recall that that MSFT changed the behavior of some of their getElementsBy* methods to conform to the W3C DOM with the IE 11 release.  I also know that this change has broken some scripts because at least one of the method was not returning the same elements it was with previous versions of IE.  What I don't recall is if getElementsByName is one of the getElementsBy* methods that was changed for IE 11.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

apeacock

I had originally used getElementByID in the IE8 script, which would return an element by either ID or Name.  In this case, since the element has no ID and Microsoft changed getElementByID so that it only returns elements by ID and not by Name, I had to change the code to use getElementsByName and then use the first element in the returned array.  I verified that this worked by checking the value of the element (that is the purpose of the "checkval" varialbe in my posted code).  Based on that information, I believe I'm sending the event to the proper element.

td

Getting the 'value' of the element you expect does not in and of itself guarantee that you have the correct element. Hence the suggestion to make sure you have the correct element.   But since you can examine your site's complete DOM you can certainly verify the validity of the element you are using.

I don't have any other suggestions so unless some other forum member provides a new insight you will have to seek help elsewhere.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade