Jump to content

Webdriverscript not working as expected...


Jemboy
 Share

Recommended Posts

Hi,

I have the below script.
It should return the second screenshot, however sometimes I get the first screenshot.
On some computers I almost 90% get screen 2, but on some others I get screen 1 (wrong screen) almost every time.

I have played around with "_WD_LoadWait", sleep or using "_WD_WaitElement", however I do not seem
to be able get the reason why my script is behaving so randomly.

Does anyone have some insights for me ?

#include "wd_helper.au3"
#include "wd_capabilities.au3"

_Example()

Func _Example()
    # REMARK
    #   This is not functional script
    #   It only shows the concept how to use WebDriver UDF

    #Region ; initialize webdriver sesion


    _WD_UpdateDriver('chrome')

    ; specify driver, port and other options
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & @ScriptDir & '\chrome.log"')

    ; start the driver
    _WD_Startup()
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; create capabilites for session
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    Local $sCapabilities = _WD_CapabilitiesGet()

    ; create session with given Capabilities
    Global $sSession = _WD_CreateSession($sCapabilities)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's
    _WD_Window($sSession, 'maximize')

    #EndRegion ; initialize webdriver sesion

    #Region ; do your's stuff

    ; navigate to some website
    Local $sURL = "https://ordermanager.tecalliance.net/newapp/auth/login"
    _WD_Navigate($sSession, $sURL)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's


    ; wait for loading process ends
    _WD_LoadWait($sSession, 1000)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; find cookie popup
    Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='mat-button-wrapper']")
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; click on default button from cookie popup (accept)
    _WD_ElementAction($sSession, $sElement, 'click')
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's


    ; wait max. 50 seconds for the login button (=aanmelden) to be available
    _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='mat-focus-indicator log-in-button mat-raised-button mat-button-base']", 100, 50 * 1000)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; find this login (=aanmelden) button
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='mat-focus-indicator log-in-button mat-raised-button mat-button-base']")
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; click this "login" button to start login process
    _WD_ElementAction($sSession, $sElement, 'click')
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; wait for the username (=gebruikersnaam) field to be available
    _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//input[@id="input28"]', 100, 30 * 1000)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; find this username field
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//input[@id="input28"]')
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; fill in user e-mail in the input field
    _WD_ElementAction($sSession, $sElement, 'value', "test@test.nl")
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; lookup orange [Volgende] (=next) button
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@class='button button-primary']")
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; click on the orange [volgende] (=next) button to continue
    _WD_ElementAction($sSession, $sElement, 'click')
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    Exit    ; Exit so not to close his Chrome session.

    #EndRegion ; do your's stuff

    #Region ; Clean Up

    ; on the end session should be deleted
    _WD_DeleteSession($sSession)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; and driver should be closed
    _WD_Shutdown()
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    #EndRegion ; Clean Up

EndFunc   ;==>_Example

image.thumb.png.fbbba38ec578c80151d4761b491ba1e2.png

image.thumb.png.e679699b21a6c6bcb052b8fa908e1a05.png

Link to comment
Share on other sites

2 minutes ago, gmmg said:

For the Login, i think you can take the following URL: https://login.tecalliance.net

I want to automate the login process.
Your link seems like a very nice shortcut to this🙂
I will have a look, if I can implement this.


Besides that it still  gnaws at me (Dutch: het knaagt aan me) that running the script multiple times
results in diffirent outcomes.
So I would love the learn what I am overlooking😁

Link to comment
Share on other sites

Haven;t had the time run and grab the full log, but I can post relevant Scite output here.
The websriver UDF is 1.3.1, however my full script (in another folder) uses the latest Webdriver UDF.

With the wrong response outputm I see "__WD_Post ==> Element interaction issue [14] : HTTP status = 400" where the diffirence is starting.
I didn't have any time left today to investigate why the script reproduce a diffirent result here while doing the same web page.

;Script with GOOD results

_WD_Startup: OS:    WIN_10 X64 19045 
_WD_Startup: AutoIt:    3.3.16.1
_WD_Startup: Webdriver UDF: 1.3.1 (Update available)
_WD_Startup: WinHTTP:   1.6.4.2
_WD_Startup: Driver:    chromedriver.exe (32 Bit)
_WD_Startup: Params:    --port=9515 --verbose --log-path="O:\Autoit\Chromedriver Webdriver Tester\chrome.log"
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe" --port=9515 --verbose --log-path="O:\\Autoit\Chromedriver Webdriver Tester\chrome.log" 
_WD_Startup ==> Success [0]
_WD_CapabilitiesAdd ==> Success [0] : Successfully used [alwaysMatch]  with specified browser: chrome
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
__WD_Post ==> Success [0] : HTTP status = 200
_WD_CreateSession ==> Success [0] : cd526b06af4653b13ef84e7d0f493b61
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Window ==> Success [0] : Parameters:   Command=maximize   Option=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Navigate ==> Success [0] : Parameters:   URL=https://ordermanager.tecalliance.net/newapp/auth/login
_WD_LoadWait ==> Success [0 / 4] : Parameters:    Delay=1000    Timeout=Default    Element=Default    DesiredState=complete    : ReadyState= complete (Fully loaded)
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//*[@class='mat-button-wrapper']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=click   Option=Default
_WD_WaitElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//*[@class='mat-focus-indicator log-in-button mat-raised-button mat-button-base']   Delay=100   Timeout=50000   Options=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//*[@class='mat-focus-indicator log-in-button mat-raised-button mat-button-base']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=click   Option=Default
_WD_WaitElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//input[@id="input28"]   Delay=100   Timeout=30000   Options=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//input[@id="input28"]   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=value   Option=<masked>
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//*[@class='button button-primary']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=click   Option=Default
+>11:19:39 AutoIt3.exe ended.rc:0
+>11:19:39 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 15.4


 

;Script with WRONG results

_WD_Startup: OS:    WIN_10 X64 19045 
_WD_Startup: AutoIt:    3.3.16.1
_WD_Startup: Webdriver UDF: 1.3.1 (Update available)
_WD_Startup: WinHTTP:   1.6.4.2
_WD_Startup: Driver:    chromedriver.exe (32 Bit)
_WD_Startup: Params:    --port=9515 --verbose --log-path="O:\Autoit\Chromedriver Webdriver Tester\chrome.log"
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe" --port=9515 --verbose --log-path="O:\Autoit\Chromedriver Webdriver Tester\chrome.log" 
_WD_Startup ==> Success [0]
_WD_CapabilitiesAdd ==> Success [0] : Successfully used [alwaysMatch]  with specified browser: chrome
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
__WD_Post ==> Success [0] : HTTP status = 200
_WD_CreateSession ==> Success [0] : 4fec888636b28ef675e1b0703e494bfa
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Window ==> Success [0] : Parameters:   Command=maximize   Option=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Navigate ==> Success [0] : Parameters:   URL=https://ordermanager.tecalliance.net/newapp/auth/login
_WD_LoadWait ==> Success [0 / 4] : Parameters:    Delay=1000    Timeout=Default    Element=Default    DesiredState=complete    : ReadyState= complete (Fully loaded)
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//*[@class='mat-button-wrapper']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=click   Option=Default
_WD_WaitElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//*[@class='mat-focus-indicator log-in-button mat-raised-button mat-button-base']   Delay=100   Timeout=50000   Options=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//*[@class='mat-focus-indicator log-in-button mat-raised-button mat-button-base']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> Element interaction issue [14] : HTTP status = 400
_WD_ElementAction ==> Element interaction issue [14] : Parameters:   Command=click   Option=Default
+>11:18:22 AutoIt3.exe ended.rc:0
+>11:18:22 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 18.56

 

Link to comment
Share on other sites

Hi @Jemboy 👋 ,

this is not enough. We need the full log of both versions. Because no information about your capabilities string which is essential to know.
Please simply set:

$_WD_DEBUG = $_WD_DEBUG_Full

... and run again. Post your logs and maybe we are able to help.

Also please consider to test your automation with different browsers. How is the behavior in MSEdge or how in Firefox?
Another question: Do you use _WD_JsonActionKey in your code? Because I reviewed the changes between v1.3.1 and v1.4.0 and there is nothing which should break somehow. Besides function _WD_JsonActionKey I am sure about this.

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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

×
×
  • Create New...