Jump to content

Why does my IE script stall after the second click action?


Recommended Posts

Hello,

below my script that logs into an asp.net mvc web application:

#include <IE.au3>
#include <MsgBoxConstants.au3>

Global $oIE = _IECreate ("http://www.test.net/")
_IELoadWait($oIE)

Local $oForm = _IEFormGetObjByName($oIE, "signinForm")
Local $username = _IEGetObjByName($oIE,"UserName")
Local $password = _IEGetObjByName($oIE,"Password")
Local $button =_IEGetObjById($oIE,"save")

_IEFormElementSetValue ($username,"xxxxx")
_IEFormElementSetValue ($password,"yyyyy")
_IEAction ($button,"click")
_IELoadWait($oIE,4000)

;execution stalls at above line unless MsgBox commands are added as given

;MsgBox($MB_OK, "Test", "1")
$obj = _IEGetObjById($oIE, "a-search-page")
_IEAction ($obj,"click")
_IELoadWait($oIE,1000)

;MsgBox($MB_OK, "Test", "2")
$obj = _IEGetObjById($oIE, "go-to-stamm")
_IEAction ($obj,"click")
_IELoadWait($oIE,1000)

;MsgBox($MB_OK, "Test", "3")
$obj = _IEGetObjById($oIE, "a-template-companies")
_IEAction ($obj,"click")
_IELoadWait($oIE,4000)

;MsgBox($MB_OK, "Test", "4")
;$obj = _IEGetObjById($oIE, "a-logout")
;_IEAction ($obj,"click")
;_IELoadWait($oIE,4000)

;MsgBox($MB_OK, "Test", "5")
_IEQuit ($oIE)

The login works properly, but the execution stalls after that. When MsgBox commands are added (as indicated above) then the first MsgBox and ists following click action are executed properly, the subsequent MsgBoxes are also executed but the click actions are not. Sometimes the script does not stall already at the first click action but at the second or third, depending how often the script has been executed before within a certain time period.

Please help! Regards, Manu

Link to comment
Share on other sites

You have to capture the values returned by the commands and display them along the value of @error. For example :

Local $oForm = _IEFormGetObjByName($oIE, "signinForm")
ConsoleWrite (IsObj($oForm) & "/" & @error & @CRLF)
Local $username = _IEGetObjByName($oIE,"UserName")
ConsoleWrite (IsObj($username) & "/" & @error & @CRLF)
Local $password = _IEGetObjByName($oIE,"Password")
ConsoleWrite (IsObj($password) & "/" & @error & @CRLF)
Local $button =_IEGetObjById($oIE,"save")
ConsoleWrite (IsObj($button) & "/" & @error & @CRLF)

Local $iRet = _IEFormElementSetValue ($username,"xxxxx")
ConsoleWrite ($iRet & "/" & @error & @CRLF)
$iRet = _IEFormElementSetValue ($password,"yyyyy")
ConsoleWrite ($iRet & "/" & @error & @CRLF)

 

Link to comment
Share on other sites

@Nine:

thanks for the help.  I added the recommended ConsoleWrite commands after each code line. When I TestRun the script in the console I get:

1/0

for the code lines that do the login; I assume that means they work without error.

Then a code line such as below follows (in my script)

$obj = _IEGetObjById($oIE,"a-search-page")
ConsoleWrite ($obj & "/" & @error & @CRLF)

where I get

--> IE.au3 T3.0-2 Warning from function _IEGetObjById, $_IESTATUS_NoMatch (a-search-page)
0/7

However, I checked several times the DOM for the  element with id="a-search-page" and it is definitely present.

For

$obj = _IEGetObjById($oIE,"a-logout")
ConsoleWrite ($obj & "/" & @error & @CRLF)
_IEAction ($obj,"click")
_IELoadWait($oIE)

I get

--> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType
--> IE.au3 T3.0-2 Warning from function _IEGetObjById, $_IESTATUS_NoMatch (a-logout)
0/7

Again, I am certain that the element is present. I also wonder how can a clickable element be of 'InvalidDataType'.

Any further suggestions how to pin down the cause for the failing script?

Link to comment
Share on other sites

Link to comment
Share on other sites

5 minutes ago, Danp2 said:

Have you checked to see if the page uses frames? That would explain why you can "see" elements but not find them with the _IE commands.

No frames used. The app is an asp.net mvc application, the layout-page has partial views in it,  where some of the elements are located that the script must access.

Below the entire script:

#include <IE.au3>
#include <MsgBoxConstants.au3>

call ("prepare")

Func prepare ()
Global $oIE = _IECreate("http://www.some.page.net/")

_IELoadWait($oIE)

Local $oForm = _IEGetObjById($oIE, "signinForm")
ConsoleWrite (IsObj($oForm) & "/" & @error & @CRLF)

Local $username = _IEGetObjByName($oIE,"UserName")
ConsoleWrite (IsObj($username) & "/" & @error & @CRLF)

Local $password = _IEGetObjByName($oIE,"Password")
Local $button =_IEGetObjById($oIE,"save")
Local $iRet = _IEFormElementSetValue ($username,"xxxxxx")
ConsoleWrite ($iRet & "/" & @error & @CRLF)

Local $iRet = _IEFormElementSetValue ($password,"yyyyy")
ConsoleWrite ($iRet & "/" & @error & @CRLF)
_IEAction ($button,"click")
_IELoadWait($oIE)

$obj = _IEGetObjById($oIE,"a-search-page")
ConsoleWrite ($obj & "/" & @error & @CRLF)
_IEAction ($obj,"click")
_IELoadWait($oIE)

$obj = _IEGetObjById($oIE,"a-logout")
ConsoleWrite ($obj & "/" & @error & @CRLF)
_IEAction ($obj,"click")
_IELoadWait($oIE)

_IEQuit ($oIE)
EndFunc

 

Link to comment
Share on other sites

This is the login page:

<div id="body" class="container">
        
<div class="plate-shadow">
    <div class="login-header">
        <h1>Kunden-Login</h1>
    </div>
    <div id="loginUserForm">
<form action="/Identity/Login" id="signinForm" method="post">            <fieldset>
                
                <div class="row clearfix">
                    <div class="label">
                        <label for="UserName">Bitte anmelden</label>
                    </div>
                    <div class="editor">
                        <input data-val="true" data-val-required="Der 'Login-Name' darf nicht leer sein!" id="UserName" name="UserName" placeholder="Username" type="text" value="">
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="label">
                        <label for="Password">Kennwort</label>
                    </div>
                    <div class="editor">
                        <input id="Password" name="Password" type="password">
                        
                    </div>
                </div>
                <div class="row clearfix">
                    <div class="label-checkbox">
                        <label for="StayLoggedInToday">Angemeldet bleiben?</label>
                    </div>
                    <input data-val="true" data-val-required="The StayLoggedInToday field is required." id="StayLoggedInToday" name="StayLoggedInToday" type="checkbox" value="true"><input name="StayLoggedInToday" type="hidden" value="false">
                </div>
                <div class="button">
                    <button id="save" type="submit" class="k-button">Anmelden</button>
                </div>
            </fieldset>
</form>    </div>
</div>



<script>


    $(function () {
        function clearAmplifyStorage() {
            //amplify.store("IsCompanySelected", false);
            amplify.store("SelectedItemId", null);
            //amplify.store("SelectedItem", null);
            amplify.store("CompanyInfo", null);
            //amplify.store("SelectedMenuItemId", null);
            //amplify.store("CurrentMenuItemId", null);

                amplify.store("selected-menu-item-id", null);
                amplify.store("IsCompanyInfoVisible", false);
                amplify.store("IsSideNavBarVisible", false);
                amplify.store("IsCompanyNew", false);

        }
        
        clearAmplifyStorage();
    });
</script>
        <div class="login-footer">
            <div class="logoBottom">
                <a href="#">IndireKat</a>
            </div>
            <div class="logoBottom-name">
                Indire<span class="appendix">Kat</span>
            </div>
            <div class="copy">© 2018 <br>xxxx</div>
        </div>
    </div>

This is part of the page that gets opened after the login, where the element with the id="a-search-page"  must be found by the script:

<ul id="horizontal-navBar" data-role="menu" class="k-widget k-reset k-header k-menu k-menu-horizontal" tabindex="0" role="menubar">
        <li class="k-item k-state-default k-first" role="menuitem">
            <a class="btn-go-to-index-page k-link k-menu-link">Aktuelles</a>
        </li>
            <li id="li-search-page" class="k-item k-state-default" role="menuitem">
                <a id="a-search-page" name="a-name-search-page" class="btn-go-to-search-page k-link k-menu-link" title="Suchformular zum Auswählen eines Betriebes">Betrieb wählen</a>
            </li>
                    <li class="k-item k-state-default" role="menuitem">
                <a id="a-template-companies" class="btn-show-template-companies k-link k-menu-link" title="Neuen Betrieb anlegen">Neuer Betrieb</a>
            </li>
                    <li class="k-item k-state-default" role="menuitem">
                <a class="btn-show-soon-due-reportduties k-link k-menu-link" title="Innerhalb der nächsten n-Monate fällige und überfällige Berichtsvorlagen aller Betriebe">Fällige Vorlagen</a>
            </li>
            <li class="k-item k-state-default" role="menuitem">
                <a class="btn-show-soon-obsolete-contracts k-link k-menu-link" title="Innerhalb der nächsten n-Monate auslaufende und bereits abgelaufene Verträge/Zustimmungen aller Betriebe">Auslaufende Verträge</a>
            </li>
        <li id="bh-reports" aria-haspopup="true" class="k-item k-state-default" role="menuitem">
            <span class="k-link k-menu-link"><span title="IEV-Berichte des Kläranlagenbetreibers an die Behörde">Behördenberichte</span><span class="k-icon k-i-arrow-60-down k-menu-expand-arrow"></span></span>
            <ul class="k-group k-menu-group" role="menu" aria-hidden="true">
                <li title="Behördenberichte gemäß IEV § 6 anzeigen/drucken" class="k-item k-state-default k-first" role="menuitem"><a class="btn-go-to-authority-report k-link k-menu-link">Vorschau</a></li>
                    <li title="Berichte als PDF-Datei per Email an die Behörde schicken" class="k-item k-state-default k-last" role="menuitem"><a class="btn-email-to-autority k-link k-menu-link"><span>Emailen</span></a></li>
            </ul>
        </li>

            <li class="k-item k-state-default k-last" role="menuitem">
                <a id="a-logout" class="btn-show-Export k-link k-menu-link" title="Export Schnittstelle">Schnittstelle</a>
            </li>
    </ul>

And this is the part with the logout link:

<nav id="top-navBar" class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top py-0">
    
    <div>
        <a id="app-logo" class="navbar-brand ml-4 pl-1 ml-xl-0 pl-xl-0" href="#">IndireKat</a>
    </div>
    <button title="Zeigt/versteckt die obere horizontale Navigationsleiste" class="navbar-toggler float-right" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown">
                    Standardlisten
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item btn-go-to-all-herkunftsbereiche" href="#">Herkunftsbereiche</a>
                    <a class="dropdown-item btn-go-to-all-grenzwertlisten" href="#">Grenzwertlisten</a>
                    <div class="dropdown-divider" href="#"></div>
                    <a class="dropdown-item btn-go-to-all-vorreinigungsanlagen" href="#">Vorreinigungsanlagen</a>
                    <div class="dropdown-divider" href="#"></div>
                    <a class="dropdown-item btn-go-to-all-parameters" href="#">&nbsp;Analysenparameter</a>
                    
                </div>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
                    Stammlisten
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item btn-go-to-katfuehrer" href="#" title="Benutzergruppe Stammdaten">Benutzergruppe</a>
                    <a class="dropdown-item btn-go-to-aras-details" href="#" title="Kläranlagen Stammdaten">Kläranlagen</a>
                        <a class="dropdown-item btn-go-to-messprogramme" href="#" title="Messprogramme (Parameterlisten) für Teilstromkonsense">Messprogramme</a>
                        <a class="dropdown-item btn-go-to-aras-schaechte" href="#" title="Kanalschächte">Kanalschächte</a>
                        <a class="dropdown-item btn-go-to-aras-internal-texts" href="#" title="Textbausteine für Zustimmungsverträge">Vertrags-Textbausteine</a>
                        <a class="dropdown-item btn-go-to-all-inhabers" href="#" title="Vertragspartner der Zustimmungsvereinbarung">Vertragspartner</a>
                        <a class="dropdown-item btn-go-to-all-Behoerden" href="#" title="Behörden/Juristen">Behörden</a>
                        <a class="dropdown-item btn-go-to-all-überwachers" href="#" title="Überwacher/Labors">Überwacher</a>
                        <a class="dropdown-item btn-go-to-texttemplates" href="#" title="Textbausteine für Schriftverkehr">Schriftverkehr-Textbausteine</a>
                        <a class="dropdown-item btn-go-to-requirements" href="#" title="Standard-Auflagentexte für Verträge">Auflagen-Textbausteine</a>
                        <a class="dropdown-item btn-go-to-template-builder" title="Standard-Email-Vorlagen" href="#">Email-Vorlagen</a>
                                            <a class="dropdown-item btn-go-to-all-carriers" title="Lieferanten (von Gärsubstraten usw.)" href="#">Lieferanten</a>
                </div>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown" title="Auswertungen im Sinne der IEV-Berichte (1- und 3-jährliche) des Kläranlagenbetreibers an die Behörde">
                    Auswertungen
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item btn-go-to-activ-companies" href="#" title="Liste aller aktiven Betriebsanlagen und deren Stammdaten (489)">Einleiterverzeichnis</a>
                    <a class="dropdown-item btn-go-to-permitted-companies" href="#" title="Bewilligungspflichtige Indirekteinleiter">Bewilligungspflichtige</a>
                    <a class="dropdown-item btn-go-to-new-companies" href="#" title="Hinzugekommene Indirekteinleiter">Hinzugekommene</a>

                    <a class="dropdown-item btn-go-to-dropped-companies" href="#" title="Weggefallene Indirekteinleiter">Weggefallene</a>
                    <a class="dropdown-item btn-go-to-wastewaters" href="#" title="Liste aller aktiven Teilströme und deren Mengenkonsense">Teilstromverzeichnis</a>
                    <a class="dropdown-item btn-go-to-freight-summary" href="#" title="Konsensierten Frachtensummen aller aktiven Teilströme">Konsens-Frachtsummen</a>

                    <a class="dropdown-item btn-go-to-analyses-exceeded" href="#" title="Konzentrations-/Fracht-Nichteinhaltungen bei Überwachungen">Konzentrations-/Fracht-Nichteinhaltungen</a>
                    <a class="dropdown-item btn-go-to-discharge-exceeded" href="#" title="Abwassermengen-Nichteinhaltungen bei Überwachungen">Abwassermengen-Nichteinhaltungen</a>
                    <a class="dropdown-item btn-go-to-limits-exceeded" href="#" title="Mengenschwellenüberschreitung bei Überwachungen">Schwellenüberschreitungen bei Überwachungen</a>
                    <a class="dropdown-item btn-go-to-swells-exceeded" href="#" title="Mengenschwellenüberschreitung bei Konsensen aktiver Teilströme">Konsens-Schwellenüberschreitungen</a>

                    <a class="dropdown-item btn-go-to-ara-limits-exceeded" href="#" title="Messstelle-Tagesmengenkonsens > ARA-Zulaufkonsensemenge / 100">Messstelle-/Ara-Zulauf Überschreitungen</a>
                    <a class="dropdown-item btn-go-to-current-events" href="#" title="Teilstrom-bezogene abwasserrelevante Vorkommnisse">Vorkommnisse</a>
                    <a class="dropdown-item btn-go-to-not-delivered-duties" href="#" title="nicht vorgelegte Berichte der Indirekteinleiter">Nichtvorlagen</a>

                </div>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
                    Übersichten
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item btn-go-to-all-companies" href="#" title="Liste aller Betriebsanlagen unabhängig von Status und Kategorie">Betriebsanlagen</a>
                    <a class="dropdown-item btn-go-to-all-ownercompanies" href="#" title="Liste aller Vertragspartner denen mindestens ein Betrieb zugeordnet ist">Vertragspartner Betriebe</a>
                    <a class="dropdown-item btn-go-to-all-behandlungsstellen" href="#" title="Liste aller Behandlungsstellen aller Betriebe">Behandlungsstellen</a>

                    <a class="dropdown-item btn-go-to-bewilligungen" href="#" title="Liste aller Bewilligungen aller Betriebe">Bewilligungen</a>
                    <a class="dropdown-item btn-go-to-faelligkeiten" href="#" title="Liste aller offenen und überfälligen Fälligkeiten aller Betriebe">Offene Fälligkeiten</a>
                    <a class="dropdown-item btn-go-to-completed-faelligkeiten" href="#" title="Liste aller erledigten Fälligkeiten aller Betrieb">Erledigte Fälligkeiten</a>

                    <a class="dropdown-item btn-go-to-all-vorkommnisse" href="#" title="Liste aller Vorkommnisse aller Betriebe">Vorkommnisse</a>
                        <a class="dropdown-item btn-go-to-all-deliveries" href="#" title="Liste aller Anlieferungen aller Betriebe">Anlieferungen</a>
                    <a class="dropdown-item btn-go-to-zustaendige" href="#" title="Liste aller Zuständigen aller Betriebe">Zuständige</a>
                </div>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
                    Support
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item btn-go-to-send-support-email" href="#" title="Email an Support-Team schicken">Email Support</a>
                        <a class="dropdown-item btn-go-to-support-ticket" href="#" title="Ihre Support Tickets">Support Tickets</a>

                    <a class="dropdown-item" href="/Content/HelpFiles/TeamViewerSupport.exe" download="" title="Teamviewer Support: Klicken Sie auf den Link, laden Sie die Datei herunter und führen Sie die Datei aus. Folgen Sie der Anleitung des Dialogfensters.">Teamviewer Support</a>

                    <a class="dropdown-item btn-go-to-dowwnload-grid" href="#" title="Downloads und Links">Downloads und Links</a>
                    <a class="dropdown-item btn-go-to-notification-grid" href="#" title="Wichtige Mitteilungen">Mitteilungen</a>
                </div>
            </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
                        Admin
                    </a>
                    <div class="dropdown-menu">
                        <a class="dropdown-item btn-go-to-all-anforderungen" href="#" title="Hilftetexte">Hilftetexte</a>
                        <a class="dropdown-item btn-go-to-create-blob-container" href="#" title="Blob-Container erstellen">Blob-Container erstellen</a>
                        <a class="dropdown-item btn-go-to-search-ara" href="#" title="ARAs">ARAs</a>
                        <a class="dropdown-item btn-go-to-search-community" href="#" title="Gemeinden">Gemeinden</a>

                        <a class="dropdown-item btn-go-to-all-userGroup" href="#" title="Mitteilungen">User Gruppen</a>
                        <a class="dropdown-item btn-go-to-all-users" href="#" title="Mitteilungen">User</a>
                        <a class="dropdown-item btn-go-to-all-contractTags" href="#" title="Mitteilungen">Contract Tags</a>
                        <a class="dropdown-item btn-go-to-access-services" href="#" title="Mitteilungen">Access Updates</a>

                        <a class="dropdown-item btn-go-to-all-meldungen" href="#" title="Mitteilungen">Meldungen</a>

                        <a class="dropdown-item btn-go-to-all-musterbetriebe" href="#" title="Mitteilungen">Muster-Betriebe übertragen</a>
                        <a class="dropdown-item btn-go-to-aktuelles" href="#" title="Mitteilungen">Aktuelles</a>
                        <a class="dropdown-item btn-go-to-proposals" href="#" title="Mitteilungen">Verbesserungsvorschläge</a>

                        <a class="dropdown-item btn-go-to-testChecker" href="#" title="Mitteilungen">TestChecker</a>

                    </div>
                </li>

        </ul>
        <ul class="navbar-nav navbar-right">
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbardrop" data-toggle="dropdown">
                    Bearbeiter
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item btn-go-to-edit-user-page" title="Persönliche Einstellungen" href="#">Einstellungen</a>

                </div>
            </li>
            <li id="li-logout" class="nav-item">
                <a id="a-logout" class="nav-link logOutLink" href="#"><i class="fa fa-sign-out-alt"></i> Abmelden</a>
            </li>
        </ul>
    </div>
</nav>

 

Link to comment
Share on other sites

@Danp2:

I tried my best, but could not solve the problem and gave up on IE-automation with IE.au3. Now I would like to try it with WebDriver and Chrome.

 I installed WebDriver and requirements (as described at: there) and I think everything is set up correctly (I test ran 'wd_demo.au3' and it ran correctly).

In 'wd_demo.au3'  I found lots of commands, but I am not sure how to use them  for loggin into a website and perform several actions (see the IE-script in my 3rd last post)

Where can I find a description for all the commands, especially those that I need for my Chrome-automation script?

 

 

Link to comment
Share on other sites

Webdriver is more complex with less documentation, so you may want to stick with IE. 🙂 That said, you should check out the wiki entry. Near the bottom, it contains links to other forum threads where the UDF is discussed, examples are given, etc.

In wd_demo, take a look at the DemoElements function for examples of locating an element, setting / retrieving it's value, clicking on a button, etc.

 

Link to comment
Share on other sites

@Manu191357 If you still want help with IE, I would like to suggest a couple of things to see if it can solve your issue.

Try using a long Sleep before _IEGetObjById($oIE,"a-search-page"), like this :

Sleep (20000)
$obj = _IEGetObjById($oIE,"a-search-page")

If it works, it means that Danp2 is right and you need to create a loop until the object appears.

If that doesn't work try reattaching to $oIE object like this :

#include <IE.au3>
#include <MsgBoxConstants.au3>

prepare()

Func prepare()
  Local $oIE = _IECreate("http://somesite.com/")
  _IELoadWait($oIE)
  Local $hWnd = _IEPropertyGet ($oIE, "hwnd")

  Local $oForm = _IEGetObjById($oIE, "signinForm")
  ConsoleWrite(IsObj($oForm) & "/" & @error & @CRLF)

  Local $username = _IEGetObjByName($oIE, "UserName")
  ConsoleWrite(IsObj($username) & "/" & @error & @CRLF)

  Local $password = _IEGetObjByName($oIE, "Password")
  Local $button = _IEGetObjById($oIE, "save")
  Local $iRet = _IEFormElementSetValue($username, "xxxxxx")
  ConsoleWrite($iRet & "/" & @error & @CRLF)

  Local $iRet = _IEFormElementSetValue($password, "yyyyy")
  ConsoleWrite($iRet & "/" & @error & @CRLF)
  _IEAction($button, "click")
  _IELoadWait($oIE)

  If Not WinExists ($hWnd) Then Exit MsgBox ($MB_SYSTEMMODAL,"","Handle has changed")
  $oIE = _IEAttach ($hWnd, "hwnd")
  ConsoleWrite(IsObj($oIE) & "/" & @error & @CRLF)

  $obj = _IEGetObjById($oIE, "a-search-page")
  ConsoleWrite(IsObj($obj) & "/" & @error & @CRLF)
  _IEAction($obj, "click")
  _IELoadWait($oIE)

  $obj = _IEGetObjById($oIE, "a-logout")
  ConsoleWrite(IsObj($obj) & "/" & @error & @CRLF)
  _IEAction($obj, "click")
  _IELoadWait($oIE)

  _IEQuit($oIE)
EndFunc   ;==>prepare

 

Link to comment
Share on other sites

@Nine,

thank you for your help. I will look into it.

In the meantime I got the script working using WebDriver UDF and Chrome automation; below my script:

#include "wd_core.au3"

Local $sDesiredCapabilities, $sSession

; Execute browser setup routine for user's browser selection
SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
DemoElements()

MsgBox($MB_ICONINFORMATION, "Demo complete!", "Click ok to shutdown the browser and console")

_WD_DeleteSession($sSession)
_WD_Shutdown()

Func DemoElements()
    Local $sElement, $aElements, $sValue, $sButton, $sResponse, $bDecode, $sDecode, $hFileOpen

    ; navigate to website
    _WD_Navigate($sSession, "http://web.site.net")
    sleep(1000)

    ;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='UserName']")
    sleep(500)

    ;Set element's contents
    _WD_ElementAction($sSession, $sElement, 'value', "wakeup")
    sleep(500)

    ;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='Password']")
    sleep(500)

    ;Set element's contents
    _WD_ElementAction($sSession, $sElement, 'value', "wakeup")
    sleep(500)

    ;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='save']")
    sleep(500)

    ; Click element
    _WD_ElementAction($sSession, $sElement, 'click')
    sleep(1000)

    ;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='a-search-page']")
    sleep(1000)

    ; Click element
    _WD_ElementAction($sSession, $sElement, 'click')
    sleep(1000)

    ;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//li[@id='1']")
    sleep(2000)

    ; Click element
    _WD_ElementAction($sSession, $sElement, 'click')
    sleep(1000)

    ;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//li[@id='11']")
    sleep(2000)

    ; Click element
    _WD_ElementAction($sSession, $sElement, 'click')
    sleep(1000)

    ;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='a-logout']")
    sleep(1000)

    ; Click element
    _WD_ElementAction($sSession, $sElement, 'click')
    sleep(1000)

EndFunc

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}'
EndFunc

I have just one little issue with the last click-event: This click-event aims for an a-html-element that is inside a bootstrap Navbar which gets toggeled into a toaster icon when the viewport gets small. As it is now, for some reason my script starts Chrome with a reduced window-size, which causes the bootstrap Navbar to be toggled into the toaster and thus the a-element is not accessible anymore and causes an error in the script. When I enlarge the  window-size while the script is running, the click-event works properly with the a-element .

Any suggestions how to start Chrome with full window size?

Link to comment
Share on other sites

43 minutes ago, Danp2 said:

You shouldn't need all of the Sleep calls. If you need to wait for an element to be present, better to use _WD_WaitElement.

Unsure... but there may be a command line parameter that will force Chrome to load maximized. Otherwise, use _WD_Window to maximize it once it has launched.

Thank for the hints. But I can't get the syntax right. I tried:

;Locate a single element
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@id='a-search-page']")
    _WD_WaitElement ($sElement)

but that gives a build error ( illegal character, syntax error). Same problem with _WD_Window.

Could you please help me with _WD_WaitElement and _WD_Window.

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