Jump to content

Unable to set date correctly using wddriver.


Recommended Posts

__WD_Post: URL=HTTP://127.0.0.1:9515/session/5fca837a705f265fecf1b07cf2eccf8e/element/b768902d-f486-4d02-a3c4-7414b9418d79/value; $sData={"id":"b768902d-f486-4d02-a3c4-7414b9418d79", "text":"2021-03-30"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_ElementAction: {"value":null}...
__WD_Get: URL=HTTP://127.0.0.1:9515/session/5fca837a705f265fecf1b07cf2eccf8e/element/b768902d-f486-4d02-a3c4-7414b9418d79/property/value
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"2021-03-27"}...

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='compact-header']/div/div/div/div/div[1]/div[1]/input")
Global $result = _DateAdd('D', +3, _NowCalcDate())
$previousdate = ("D:\Xmatters-tempdates\previousdate.txt")
Global $removeslash = StringReplace($result, "/", "-")
FileWrite ($previousdate, $removeslash & @CRLF)
$readfile = FileReadLine ($previousdate,1)

_WD_ElementAction($sSession, $oERect, 'click')
;_WD_SetElementValue($sSession, $sElement, $readfile)
_WD_ElementAction($sSession, $sElement, 'value', $readfile)
_WD_ElementAction($sSession, $sElement, 'property', 'value')

 

The same works fine if iam using IE

$xpathForumLink = ("//*[@id='compact-header']/div/div/div/div/div[1]/div[1]/input")
$aForumLink = BGe_IEGetDOMObjByXPathWithAttributes($oIE1, $xpathForumLink)
Global $result = _DateAdd('D', +3, _NowCalcDate())

_IEAction($aForumLink[0], "focus")
;_IEAction($aForumLink[0], "click")
_IEPropertySet($aForumLink[0], "innertext", $removeslash)
_IELoadWait($oIE1)
Sleep(4000)
_IEAction($aForumLink[0], "click")

 

Edited by Cyborg5000
Link to comment
Share on other sites

A few observations --

  • We can't run the code you posted, so it's difficult to know why it doesn't work as expected
  • You neglected to tell us the website, so we can't investigate further
  • Many websites implement frameworks or javascript libraries that can be difficult to automate.
  • The solution will often involve some library-specific coding.
  • Guessing that you are encountering a similar issue as here.

 

Link to comment
Share on other sites

22 hours ago, Danp2 said:

A few observations --

  • We can't run the code you posted, so it's difficult to know why it doesn't work as expected
  • You neglected to tell us the website, so we can't investigate further
  • Many websites implement frameworks or javascript libraries that can be difficult to automate.
  • The solution will often involve some library-specific coding.
  • Guessing that you are encountering a similar issue as here.

 

Hello @Danp2

Hope you are doing well.

 

This code is the same as you helped with 

 

 

Just trying it to make it work with chrome/wddriver...

Link to comment
Share on other sites

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\MyAutoIt3_Green.ico
#AutoIt3Wrapper_Outfile=XmattersWho'soncall.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <UIAWrappers.au3>
#include <GuiEdit.au3>
#include <Clipboard.au3>
#include <WinAPI.au3>
#include <ColorConstants.au3>
#include <FontConstants.au3>
#include <ProgressConstants.au3>
#include <Restart.au3>
#include <_IEquerySelectorAll.au3>
#include <GuiRichEdit.au3>
#include <hiddenDesktopInteract.au3>
#include <Date.au3>
#include <CUIAutomation2.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <OutlookEX.au3>
#include <IEbyXPath.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Excel.au3>
#include <restart.au3>
#include "wd_core.au3"
#include "wd_helper.au3"
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

;_SetDate(+3)
;_SetTime(12, 00)

FileDelete("D:\Script-temp\*.*")
FileDelete("C:\Windows\Temp\*.txt")
FileDelete("D:\Xmatters-tempdates\*.*")
FileDelete("D:\Xmatters-Report\*.*")
FileDelete("D:\Rohan-Xmatters-script\LOG\*.*")
;FileDelete("C:\Users\certauto\AppData\Local\Microsoft\Windows\INetCache\*.*")
Global $username = "sling"
Global $pass = "dsfsdgfsg"

Local $sDesiredCapabilities, $sSession
SetupChrome()
_WD_Startup()



$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Window ($sSession, "Maximize")
_WD_Navigate($sSession, "https://xyz.okta.com/login/sso_iwa_auth")
_WD_LoadWait($sSession,4000)

_WD_Navigate($sSession, "https://xyz.okta.com/home/xyz_nocalert_1/0oa1ddtojvfGTCooO1d8/aln1ddttkav7HWc4p1d8?fromHome=true")
_WD_LoadWait($sSession,10000)

_WD_Navigate($sSession, "https://xyzit.xmatters.com/xmatters/app.do#WhosOnDutyGroupSelectionPlace:")
_WD_LoadWait($sSession,10000)


$sHnd1 = '{"handle":"' & _WD_Window($sSession, "window") & '"}'
_WD_Attach($sSession, "https://xyzit.xmatters.com/xmatters/app.do#WhosOnDutyGroupSelectionPlace:", "URL")

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@class='search-filter']")
_WD_ElementAction($sSession, $sElement,'click')
MouseClick("left")
_WD_ElementAction($sSession, $sElement, 'value', "Xyz Software Inc.")


;=======================================================================================================================
Sleep(4000)
;===============Previous date===================


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='compact-header']/div/div/div/div/div[1]/div[1]/input")
Global $result = _DateAdd('D', +3, _NowCalcDate())
$previousdate = ("D:\Xmatters-tempdates\previousdate.txt")
Global $removeslash = StringReplace($result, "/", "-")
FileWrite ($previousdate, $removeslash & @CRLF)
$readfile = FileReadLine ($previousdate,1)

_WD_ElementAction($sSession, $sElement, 'value', $removeslash)


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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false, "args":["start-maximized", "disable-infobars","user-data-dir=C://Users//sling//AppData//Local//Google//Chrome//User Data"] }}}}'
EndFunc

Only the thing is that i have to set a date counting 2/3 days ahead, it's run on every Friday selecting date Monday - next Sunday. 

Edited by Cyborg5000
Link to comment
Share on other sites

4 hours ago, Danp2 said:

So, now you should be able to supply a script that anyone can run to observe the outcome

Perhaps I wasn't clear when I made the above statement. My expectation was for you to use the website I posted above for testing this issue.

If you want further assistance, then you need to provide a short reproducer script that we can actually run.

Link to comment
Share on other sites

1 hour ago, Danp2 said:

Perhaps I wasn't clear when I made the above statement. My expectation was for you to use the website I posted above for testing this issue.

If you want further assistance, then you need to provide a short reproducer script that we can actually run.

Hi @Danp2

Thanks, sorry assumed you required what i tried so far... :)

Below is the code modified to work with the test account you had to create cause of me...so thankful to you for supporting and your intentions.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Program Files (x86)\AutoIt3\Icons\MyAutoIt3_Green.ico
#AutoIt3Wrapper_Outfile=XmattersWho'soncall.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StringConstants.au3>
#include <FileConstants.au3>
#include <Array.au3>
#include <String.au3>
#include <UIAWrappers.au3>
#include <GuiEdit.au3>
#include <Clipboard.au3>
#include <WinAPI.au3>
#include <ColorConstants.au3>
#include <FontConstants.au3>
#include <ProgressConstants.au3>
#include <Restart.au3>
#include <_IEquerySelectorAll.au3>
#include <GuiRichEdit.au3>
#include <hiddenDesktopInteract.au3>
#include <Date.au3>
#include <CUIAutomation2.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <OutlookEX.au3>
#include <IEbyXPath.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
#include <Excel.au3>
#include <restart.au3>
#include "wd_core.au3"
#include "wd_helper.au3"
#include <GuiComboBoxEx.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

;_SetDate(+3)
;_SetTime(12, 00)

FileDelete("D:\Script-temp\*.*")
FileDelete("C:\Windows\Temp\*.txt")
FileDelete("D:\Xmatters-tempdates\*.*")
FileDelete("D:\Xmatters-Report\*.*")
FileDelete("D:\Rohan-Xmatters-script\LOG\*.*")
;FileDelete("C:\Users\certauto\AppData\Local\Microsoft\Windows\INetCache\*.*")
Global $username = "Autoit"
Global $pass = "Tester"

Local $sDesiredCapabilities, $sSession
SetupChrome()
_WD_Startup()



$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Window ($sSession, "Maximize")
_WD_Navigate($sSession, "https://autoittester.xmatters.com/xmatters/signOn.do")
_WD_LoadWait($sSession,4000)

;=====Insert login details=========
; user name
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="username"]")
_WD_ElementAction($sSession, $sElement, 'value', $username)

;password
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="password"]")
_WD_ElementAction($sSession, $sElement, 'value', $pass)


;Submit
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="submitButton"]")
_WD_ElementAction($sSession, $sElement,'click')
;=====end login info==========


_WD_Navigate($sSession, "https://autoittester.xmatters.com/xmatters/app.do#WhosOnDutyGroupSelectionPlace:")
_WD_LoadWait($sSession,10000)


$sHnd1 = '{"handle":"' & _WD_Window($sSession, "window") & '"}'
_WD_Attach($sSession, "https://autoittester.xmatters.com/xmatters/app.do#WhosOnDutyGroupSelectionPlace:", "URL")

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="filter-bar"]/div/input")
_WD_ElementAction($sSession, $sElement,'click')
MouseClick("left")
_WD_ElementAction($sSession, $sElement, 'value', "Service-Team")


;=======================================================================================================================
Sleep(4000)
;===============Previous date===================


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id="compact-header"]/div/div/div/div/div[1]/div[1]/input")
Global $result = _DateAdd('D', +3, _NowCalcDate())
$previousdate = ("D:\Xmatters-tempdates\previousdate.txt")
Global $removeslash = StringReplace($result, "/", "-")
FileWrite ($previousdate, $removeslash & @CRLF)
$readfile = FileReadLine ($previousdate,1)

_WD_ElementAction($sSession, $sElement, 'value', $removeslash)


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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false, "args":["start-maximized", "disable-infobars","user-data-dir=C://Users//slingaya//AppData//Local//Google//Chrome//User Data"] }}}}'
EndFunc

 

Link to comment
Share on other sites

That's not exactly a short reproducer. 🤨 I was hoping for something more like this --

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

xMatters()
Exit

Func xMatters()
    Local $sUser = 'Autoit', $sPass = 'Tester', $sElement

    _WD_Navigate($sSession, "https://autoittester.xmatters.com/")
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='username']")
    _WD_ElementAction($sSession, $sElement, 'value', $sUser)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='password']")
    _WD_ElementAction($sSession, $sElement, 'value', $sPass)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='submitButton']")
    _WD_ElementAction($sSession, $sElement, 'click')
    _WD_LoadWait($sSession, 2000)

    $sElement = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='UserIntentPrompt-module__cancelBtn--2CSNe']", Default, Default, $_WD_OPTION_Element)
    If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'click')

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='GROUPS']")
    _WD_ElementAction($sSession, $sElement, 'click')
    _WD_LinkClickByText($sSession, "Who's On Call", False)
    _WD_LoadWait($sSession, 2000)

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='all-groups-check']//div[@class='Checkbox-module__wrapper--1Bxzk']")
    _WD_ElementAction($sSession, $sElement, 'click')

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='whos-on-duty-footer']//button[@type='button']")
    _WD_ElementAction($sSession, $sElement, 'click')

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='date-time toDate']/div[contains(@class,'date')]/input")
    _WD_ElementAction($sSession, $sElement, 'value', '2021-04-16')

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, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false, "prefs": {"credentials_enable_service": false, "profile.password_manager_enabled": false}}}}}'
EndFunc

 

Link to comment
Share on other sites

HI Dan,

 

I tired your code, but setting the date for the 1st frame "date-time fromDate" isn't working.

(Changed loadwait due to slow loading of the page @ my end.)

 

Func xMatters()
    Local $sUser = 'Autoit', $sPass = 'Tester', $sElement

    _WD_Navigate($sSession, "https://autoittester.xmatters.com/")
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='username']")
    _WD_ElementAction($sSession, $sElement, 'value', $sUser)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='password']")
    _WD_ElementAction($sSession, $sElement, 'value', $sPass)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='submitButton']")
    _WD_ElementAction($sSession, $sElement, 'click')
    _WD_LoadWait($sSession, 4000)

    $sElement = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='UserIntentPrompt-module__cancelBtn--2CSNe']", Default, Default)
    If @error = $_WD_ERROR_Success Then _WD_ElementAction($sSession, $sElement, 'click')

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='GROUPS']")
    _WD_ElementAction($sSession, $sElement, 'click')
    _WD_LinkClickByText($sSession, "Who's On Call", False)
    _WD_LoadWait($sSession, 4000)


    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='date-time fromDate']/div[contains(@class,'date')]/input")
    _WD_ElementAction($sSession, $sElement, 'value', '2021-04-14')

 

Link to comment
Share on other sites

I never said that it worked. I was just showing you what I had hoped you had posted as a reproducer. 😒

Go back and reread my previous post, which points you to the javascript code necessary to make this work. I will eventually release an update to the UDF that will make this easier, but you're on your own for now.

Link to comment
Share on other sites

6 hours ago, Danp2 said:

I never said that it worked. I was just showing you what I had hoped you had posted as a reproducer. 😒

Go back and reread my previous post, which points you to the javascript code necessary to make this work. I will eventually release an update to the UDF that will make this easier, but you're on your own for now.

HI @Danp2

Greetings of the day! :)

Yup understood your point that i should had created a test account for you or others to reproduce the issue, however dint knew that there can be a free account, since the company had the link integrated xmatters via okta in the apps list...and thought it would be a paid service.

Link to comment
Share on other sites

Good Morning @Cyborg5000 :bye:

I was actually trying to point out that you didn't use the test site once it was available and that your script wasn't a "simple reproducer" because it contained a bunch of code that wasn't necessary to demonstrate the issue. I know that communication can sometimes suffer because of the medium, language barrier, etc. so no worries.

 

Link to comment
Share on other sites

22 hours ago, Danp2 said:

Good Morning @Cyborg5000 :bye:

I was actually trying to point out that you didn't use the test site once it was available and that your script wasn't a "simple reproducer" because it contained a bunch of code that wasn't necessary to demonstrate the issue. I know that communication can sometimes suffer because of the medium, language barrier, etc. so no worries.

 

Hello @Danp2

Hope you are doing well!,

Yup agree with you over this. Thought it would be good to give and show the tried attempts. :)

Anyways, any pointers for setting the date 🤔 

 

 

Link to comment
Share on other sites

This is working for me. Please test and let me know your experience with it. The existing _WD_SetElementValue function will eventually support this functionality --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='date-time toDate']/div[contains(@class,'date')]/input")
    _WD_SetElementValue2($sSession, $sElement, '2021-04-16', 1)
    
Func _WD_SetElementValue2($sSession, $sElement, $sValue, $iStyle = Default)
    Local Const $sFuncName = "_WD_SetElementValue"
    Local $sResult, $iErr, $sScript, $sJsonElement

    If $iStyle = Default Then $iStyle = 0

    Switch $iStyle
        Case 0 ; Standard
            $sResult = _WD_ElementAction($sSession, $sElement, 'value', $sValue)
            $iErr = @error

        Case 1 ; Advanced
            $sScript = "Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set.call(arguments[0], arguments[1]);arguments[0].dispatchEvent(new Event('input', { bubbles: true }));"
            $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}'
            _WD_ExecuteScript($sSession, $sScript, $sJsonElement & ',"' & $sValue & '"')
            $iErr = @error

    EndSwitch

    Return SetError(__WD_Error($sFuncName, $iErr), 0, $sResult)
EndFunc

 

Link to comment
Share on other sites

2 hours ago, Danp2 said:

This is working for me. Please test and let me know your experience with it. The existing _WD_SetElementValue function will eventually support this functionality --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='date-time toDate']/div[contains(@class,'date')]/input")
    _WD_SetElementValue2($sSession, $sElement, '2021-04-16', 1)
    
Func _WD_SetElementValue2($sSession, $sElement, $sValue, $iStyle = Default)
    Local Const $sFuncName = "_WD_SetElementValue"
    Local $sResult, $iErr, $sScript, $sJsonElement

    If $iStyle = Default Then $iStyle = 0

    Switch $iStyle
        Case 0 ; Standard
            $sResult = _WD_ElementAction($sSession, $sElement, 'value', $sValue)
            $iErr = @error

        Case 1 ; Advanced
            $sScript = "Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set.call(arguments[0], arguments[1]);arguments[0].dispatchEvent(new Event('input', { bubbles: true }));"
            $sJsonElement = '{"' & $_WD_ELEMENT_ID & '":"' & $sElement & '"}'
            _WD_ExecuteScript($sSession, $sScript, $sJsonElement & ',"' & $sValue & '"')
            $iErr = @error

    EndSwitch

    Return SetError(__WD_Error($sFuncName, $iErr), 0, $sResult)
EndFunc

 

Hello @Danp2

I wonder how its easier for the MVP's to answer all the calls/questions that arise, Hat's off.✌️👏👍

Since i don't know json/js, it would had taken me no where than to struggle to find this.

 

 

Edited by Cyborg5000
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...