Jump to content

Clicking on button of a website in IE stops working overnight for no reason


Go to solution Solved by Neutro,

Recommended Posts

Hey guys,

We have an intranet website at my work that we use for managing users rights, and i've wrote some time ago a small script to automate the update process, which includes clicking on an "Update" button.

It was working fine until yesterday it didn't anymore while nothing apparently changed.

Here is the script i used:

#include <IE.au3>


$oIE = _IECreate("https://ourintranetwebsite.com")

Local $oButs = _IETagNameGetCollection($oIE, "button")
For $oBut In $oButs
    If StringInStr($oBut.innertext, "Update") then _IEAction($oBut, "click")
Next

Now when it's running i got the following error:

Quote

"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1925) : ==> The requested action with this object has failed.:
$oObject.Click()
$oObject^ ERROR

When i add an _IEErrorHandlerRegister() to get more informations, i get this as a result:

Quote

--> COM Error encountered in Nouveau AutoIt v3 Script (2).au3 (1925) :
----> $IEComErrorNumber            = 0x80020101 (-2147352319)
----> $IEComErrorWinDescription    = 
----> $IEComErrorDescription       = 
----> $IEComErrorSource            = 
----> $IEComErrorHelpFile          = 
----> $IEComErrorHelpContext       = 
----> $IEComErrorLastDllError      = 0
----> $IEComErrorRetcode           = 0x00000000
--> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_COMError (-2147352319)

I've tried searching the web for that error but found nothing that helped.

I thought the problem might have come from the computer i ran the script from, so i ran it from a sandbox but same error.

I tried the script on another website to click on a button and it's working fine, so it seems the problem is located on that specific website but i have no idea why.

Anyone got an idea that could help me?

TIA!

 

Link to post
Share on other sites
  • Solution
Posted (edited)

I found a workaround doing this with powershell instead:

$oIE         = new-object -com internetexplorer.application
$oIE.visible = $true
$oIE.navigate2("https://intranetwebsite.com")
$control = $oIE.document.IHTMLDocument3_getElementsByTagName('button') | where-object { $_.innerText -eq 'Update' }
$control.click()

Translated into autoit:

$sPSCmd = " ""$oIE = new-object -com internetexplorer.application;$oIE.visible = $true;$oIE.navigate2('https://ourintranetwebsite'); sleep -Milliseconds 10000; $control = $oIE.document.IHTMLDocument3_getElementsByTagName('button'); $control = $oIE.document.IHTMLDocument3_getElementsByTagName('button') | where-object { $_.innerText -eq 'Update' };$control.click()"" "

RunWait(@comspec & ' /c powershell.exe -executionpolicy bypass -NoProfile -WindowStyle hidden -command ' & $sPSCmd)

The double quotes at the start and end of the command are required to avoid syntax error with the windows prompt shell (cmd window)

 

PS: the below solution also works to create the IE window using autoIT and use powershell to click the button, so you can do other things with the IE window with autoIT after:

#include <IE.au3>

$oIE = _IECreate("https://ourintranetwebsite, 1, 1, 1)

$sPSCmd = " ""$PSIE = (New-Object -ComObject 'Shell.Application').Windows() | Where-Object { $_.Name -eq 'Internet Explorer' }; $control = $PSIE.document.IHTMLDocument3_getElementsByTagName('button') | where-object { $_.innerText -eq 'Update' };$control.click()"" "

RunWait(@comspec & ' /c powershell.exe -executionpolicy bypass -NoProfile -WindowStyle hidden -command ' & $sPSCmd, "", @SW_HIDE)

;do other things regularly using _IE functions with autoIT if required here

_IEQuit($oIE)

 

Edited by Neutro
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...