Sopr Posted April 16, 2021 Posted April 16, 2021 (edited) Hello I am a bit new to AutoIT coding and need some help on creating an application that would log in to our customer portal and upload a data table with order status. I am having trouble with auto login part and upload button push. I can get the IE window to open with no issues, the user and password is filled, but then i can not get the submit button to click. I tried getting it by Name or Id, I tried Send ("{ENTER}") command. But I still can not make the button click. I do not wnat to use the Mouse click option , because the window is different sizes on different computers this is intended for. #include<IE.au3> Call ("SignIn") Func SignIn() Global $oIE=_IECreate("https://Cutomer Portal") Local $username=_IEGetObjByName($oIE,"j_username") Local $password=_IEGetObjByName($oIE,"j_password") Local $button=_IEFrameGetObjByName($oIE, "j_submit") _IEFormElementSetValue($username,"Myusername") _IEFormElementSetValue($password,"Mypassword") _IEAction($button,"click") EndFunc I have tried using Chrome and WD driver for it as well. Unfortunately the Graphical Debugger does not seems to like the driver and every time I try to run it it gets stuck in some loop constantly jumping between WinHTTP and wd_core files. When I tried running the following code from wd_demo modified to my page. I get the same picture. User and password are entered correctly, but the submit button is not clicked. I suspect it is because there is no command to do that, but the Chrome driver does not have help file that shows the commands and their syntax. Wikipage is somewhat helpful it has the comments with options, but no clear syntax. I made a new function ChromeActionclickbyId, but I may have screwed up somewhere and it does not work as it should. #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://Customer Portal") <snip> _ChromeActionclickbyId($sSession,'j_submit') _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args":[' & """start-maximized""," & " ""disable-infobars""" & "" & '] }}}}' EndFunc ;==>SetupChrome Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeActionclickbyId($sSession,$Id) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'click') EndFunc Edited April 18, 2021 by Sopr Removed plaintext passwords
seadoggie01 Posted April 16, 2021 Posted April 16, 2021 You need to check the @error and @extended values after you call functions to ensure that there wasn't an error, otherwise you will have no idea of what's actually happening. For example: (feel free to do something instead of exiting with a message box, maybe exit while printing the error value to the console) Func _ChromeSetInputValueById($sSession, $Id, $Value) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") If @error Then Exit MsgBox(0, "_WD_FindElement", "Failed to find element with ID: " & $Id) _WD_ElementAction($sSession, $sElement, 'value', $Value) If @error Then Exit MsgBox(0, "_WD_ElementAction", "Failed to set element value of ID: " & $Id & " to: " & $Value) Return True EndFunc All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types
Moderators JLogan3o13 Posted April 16, 2021 Moderators Posted April 16, 2021 @Sopr, perhaps including your username and password in plaintext in your post was not the best decision. I have removed them, but you might want to change your password; no telling how many people decided to use them to log into your account since you posted. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now