levila Posted August 25, 2022 Share Posted August 25, 2022 Hi, Im trying to automate process of sign in on the web (for asset inventory in my office) When i try to process the automation sign in it tun successfully but after login to the page, there is same "ID" of that button in the page after that. And the automation seem still looping to click the button. Im very newb in webdriver udf so i need experts to look onto my code below. #include <wd_core.au3> #include <wd_helper.au3> 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,"excludeSwitches":["enable-automation"]}}}}' ;$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions":{"w3c": True}}}}' $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--no-sandbox"]}}}}' EndFunc Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetMouseClickByType($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//button[@type='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click', $Value) EndFunc Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.myassettag.com/assettiger/login") Sleep(5000) _ChromeSetInputValueById($sSession, "Email", "user@email.com") _ChromeSetInputValueById($sSession, "Password", "Password") _ChromeSetMouseClickByType($sSession, "submit", "click") and here is the same ID for button login and submit. Quote <button type="submit" class="btn btn-primary">Sign In</button> And after login there is same id as below. Quote <button type="submit" class="btn btn-primary">Submit</button> I hope u guys can understand the issue here. i want to the function only calling once and stop processing, and whenever there is ID match the criteria it wont never click it. before this im using IE.au3 but seem theres is no issue with this. Link to comment Share on other sites More sharing options...
Danp2 Posted August 25, 2022 Share Posted August 25, 2022 6 hours ago, levila said: When i try to process the automation sign in it tun successfully but after login to the page, there is same "ID" of that button in the page after that. This shouldn't matter. Quote And the automation seem still looping to click the button. You will need to elaborate on this. Do you mean the web page never responds to the click or the click never occurs? Have you checked the logs in the Scite console for any obvious issues? Also, I note that there are two buttons (one is hidden) that match your selection criteria. One possibility is that the one being returned by _WD_FindElement is the incorrect one. If that is the case, then you will need to use a selector that is more specific so that the correct button is located. Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
levila Posted August 26, 2022 Author Share Posted August 26, 2022 @Danp2 Thank you for your reply, sorry if my explanation was confusing. What im trying to do is to login on the website and proceed to register assets, here is the problem WD_Navigate to the main page and click submit button id as above to login After succesfully login, it will directly to add assets form page. The web have another submit button. Somehow the 1st calling _WD_ElementAction seem like didnt stop processing, it suddenly click again the submit button on the new page. Link to comment Share on other sites More sharing options...
Danp2 Posted August 26, 2022 Share Posted August 26, 2022 It works as I would expect when I tested it. As mentioned above, there are multiple submit buttons on the Add an Asset page. Therefore, you won't be able to use the function _ChromeSetMouseClickByType because it doesn't allow you to specify the exact selector for the desired target. You should do something like this instead -- ; find and click the correct Submit button $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='btn btn-primary']") _WD_ElementAction($sSession, $sElement, 'click') _WD_LoadWait($sSession) Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
levila Posted August 26, 2022 Author Share Posted August 26, 2022 (edited) The problem is both have similar button class and type <button type="submit" class="btn btn-primary">Sign In</button> <button type="submit" class="btn btn-primary">Submit</button> But one in 1st webpage (before login) and another one is on the next page (after success login, directly to new link/url address) Edited August 26, 2022 by levila Link to comment Share on other sites More sharing options...
Danp2 Posted August 26, 2022 Share Posted August 26, 2022 That isn't the issue AFAICS. Please run the following code (update the login details at the top) and post your Scite output if it still doesn't work correctly. Note: Your email address and password are likely visible in the logs, so be sure to alter this portion before posting. expandcollapse popup#include "wd_core.au3" #include "wd_helper.au3" Global $sDesiredCapabilities, $sSession, $sElement Global $sEmail = "<your email>" Global $sPswd = "<your password>" $_WD_Debug = $_WD_DEBUG_Full SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Window($sSession, "maximize") _WD_Navigate($sSession, "https://www.myassettag.com/assettiger/login") _WD_LoadWait($sSession) _ChromeSetInputValueById($sSession, "Email", $sEmail) _ChromeSetInputValueById($sSession, "Password", $sPswd) _ChromeSetMouseClickByType($sSession, "submit", "click") _WD_LoadWait($sSession) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "(//a[@class='btn btn-active-light me-1 fw-bold'])[2]") _WD_ElementAction($sSession, $sElement, 'click') _WD_LoadWait($sSession) ; fill in form here _ChromeSetInputValueById($sSession, 'Description', "test1") _ChromeSetInputValueById($sSession, 'AssetTagId', "test2") ; Allow time for spinner to disappear Sleep(5000) ; submit form $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='btn btn-primary']") _WD_ElementAction($sSession, $sElement, 'click') _WD_LoadWait($sSession) 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, "args":["--no-sandbox"]}}}}' EndFunc Func _ChromeSetInputValueById($sSession,$Id,$Value) Local $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetMouseClickByType($sSession,$Id,$Value) Local $sButton = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//button[@type='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click', $Value) EndFunc Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
Danp2 Posted August 30, 2022 Share Posted August 30, 2022 @levilaAny update to share on your efforts? Latest Webdriver UDF Release Webdriver Wiki FAQs Link to comment Share on other sites More sharing options...
levila Posted September 2, 2022 Author Share Posted September 2, 2022 (edited) Sorry was quite busy there days, i will try your code, and i think i need to update chromedriver as suddenly it wont running the automation. Thank you @Danp2, for your time. i will try n update it here, Edited September 2, 2022 by levila Link to comment Share on other sites More sharing options...
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