Jump to content

WebDriver - WD_element didnt stop processing after calling that function.


Recommended Posts

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 post
Share on other sites
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.

Link to post
Share on other sites

@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 post
Share on other sites

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)

 

Link to post
Share on other sites
Posted (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 by levila
Link to post
Share on other sites

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.

 

#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

 

Link to post
Share on other sites

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