Jump to content

[SOLVED] Can I run an Autoit script that requires focus and mouse clicks in the background and do work?


Recommended Posts

Good morning, I have been thinking about trying to make my Autoit script run in the background. I found out today that it is impossible due to the UIA and mouseclick functions that I use. However, while reading other posts about running Autoit scripts in the background I saw a reply mentioning how a script like mine might be able to run on a VM while still giving me the ability to work on my Host OS. Can someone confirm this? 

Here is a link to the thread where I saw VM mentioned. 

the person who mentioned it was @ViciousXUSMC 

Edited by nooneclose
Link to comment
Share on other sites

Thank you very much @aa2zz6 for getting back with me in such a timely manner.  I will try this (as a means of double-checking) to confirm what you said. I just wanted a second opinion or five :) to make sure it was even possible before I went through the trouble of creating a VM to test it. 

Edited by nooneclose
Link to comment
Share on other sites

@aa2zz6 I have a script that automates the tasks of handling customer requests in my company's database. For whatever reason, maybe I am just stupid, I have a hard time understanding/getting "controlclick"s to work so I use "mouseclick"s instead. However, if I was able to switch out all "mouseclick"s for "controlclick"s (which I would love by the way) I still use _UIA_Action("oAction5", "setfocus") and otheer functions like it which require the website to be in the foreground.

If you know of some way to get "_UIA_Action("", "setfocus")" and other functions like it to work without the website in the foreground please share. :)  

I'm sorry I forgot to answer your question. I am using "mouseclick"s to click on different buttons in my company's database. (we use Maximo. IBM hosts a test site if you want to try it out. Here is a link to it: https://www.ibm.com/support/pages/maximo-asset-management-760-preview-site

An example of some of the buttons I am wanting to click would be: 

"work order tracking" under the "work order" drop down menu

or

"New work order" in the "work order tracking" application

 

I hope I was able to fully answer your question. :) 

Edited by nooneclose
Link to comment
Share on other sites

running inside a VM would be fine, only problem, if you move your mouse across the VM window it would grab the pointer and move it.

If Maximo is a full website, have you tried the WebDriver?  I used it with chrome and it's amazing, though a bit complicated to setup, and you MUST learn xpaths.

 

Link to comment
Share on other sites

Thank you @BigDaddyO I will look into WebDiver and give it a shot. Maximo I believe is a full website. (though I am 100% sure what you mean by full) If WebDiver is faster and can help it run in the background then I am all ears. :D 

Also, I am having some issues with the VM so I will not be able to confirm that today. I will post the results though once I resolve the issues.  

Link to comment
Share on other sites

@BigDaddyO Thank you for your reply. Maximo does not require any downloads. :) Once I have the JSON UDF and the WinHTTP UDF and the WebDiver.exe and the WebDiver UDF is there anything else I need to do to get WebDiver to work?

I ran the WebDiver demo and I got this error: 

_WDStartup: OS:    WIN_10 WIN32_NT 18362 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.20
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    --log-path="C:\Users\a\Desktop\AutoIt_Stuff\WebDiver\2019\WebDiver\WebDriver-0.1.0.20\chrome.log"
_WDStartup: Port:    ****
_WD_Startup ==> General Error: Error launching web driver!
!>08:21:42 AutoIt3.exe ended.rc:-1
+>08:21:42 AutoIt3Wrapper Finished.
>Exit code: 4294967295    Time: 0.7773

 

Also @aa2zz6 I am sorry but I cannot confirm that the VM works. (using Vrtual_Box with windows 8.1 OS) I keep getting the error:

Call to WHvSetupPartition failed: ERROR_SUCCESS (Last=0xc000000d/87) (VERR_NEM_VM_CREATE_FAILED).

I tried changing my BIOS options but it did not work. I may have to give up on that unless I can make Virtual_Box work somehow. 

Link to comment
Share on other sites

@Danp2 Thank you. I did what you suggested and the demo script worked just fine. :D 

Now if only I could get Vitural_Box to work haha. 

I will try and make a very short version of my script with WebDiver to see if it can run in the background. 

I'm excited to see if it works or not. :) 

Again thank you, everyone, who has taken time out of their day to comment on this post. 

Link to comment
Share on other sites

I finished my WebDriver script and it does have the capability to run in the background. My script can run while minimized but I can not do anything else until its done. (or it won't fully work) @Danp2 maybe you could share some tips with me on how to better script it so I can perform other operations while the script is running,

The VM did work fine I used the same script which I will post below. My original question was answered but the results were not what I had hoped for. Getting a complex autoit script to run in the background is not easy or even realistic. (someone please prove me wrong :) ) A VM will work but you may have unexpected issues. (Example: If you move your mouse over it while it's running (if you use mouseClick)).

WebDriver does run faster and is more consistent then UIA but I cannot get it to run efficiently in the background while I worked. 

 (I used Edge/EdgeHTML)

Here is the code I used: (anyone should be able to run this code. It uses a demo site so unless that site changes it should work and no real harm can be done.) 

; Required Files for WebDriver to work
#include "wd_core.au3"
#include "wd_helper.au3"
#include <FileConstants.au3>

; Edge (standard)
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--host=127.0.0.1')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c":true, "binary":"' & StringReplace (@UserProfileDir, "\", "/") & '/AppData/Local/Microsoft/Edge SxS/Application/msedge.exe"}}}}'

Local Enum $eFireFox = 0, _
            $eChrome, _
            $eEdge

Local $aDemoSuite[][2] = [["DemoTimeouts", False], _
                         ["DemoNavigation", True], _
                         ["DemoElements", True], _
                         ["DemoScript", False], _
                         ["DemoCookies", False], _
                         ["DemoAlerts", False], _
                         ["DemoFrames", False], _
                         ["DemoActions", False], _
                         ["DemoWindows", False]]

Local Const $sElementSelector = "//input[@name='q']"

Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info

SetupEdge()

_WD_Startup()


If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error = $_WD_ERROR_Success Then
    For $iIndex = 0 To UBound($aDemoSuite, $UBOUND_ROWS) - 1
        If $aDemoSuite[$iIndex][1] Then
            ConsoleWrite("Running: " & $aDemoSuite[$iIndex][0] & @CRLF)
            Call($aDemoSuite[$iIndex][0])
        Else
            ConsoleWrite("Bypass: " & $aDemoSuite[$iIndex][0] & @CRLF)
        EndIf
    Next
EndIf

_WD_DeleteSession($sSession)
_WD_Shutdown()


If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error = $_WD_ERROR_Success Then
    For $iIndex = 0 To UBound($aDemoSuite, $UBOUND_ROWS) - 1
        If $aDemoSuite[$iIndex][1] Then
            ConsoleWrite("Running: " & $aDemoSuite[$iIndex][0] & @CRLF)
            Call($aDemoSuite[$iIndex][0])
        Else
            ConsoleWrite("Bypass: " & $aDemoSuite[$iIndex][0] & @CRLF)
        EndIf
    Next
EndIf


;*******************************************************************************
; DEMO Function Definitions
;*******************************************************************************
Func DemoNavigation()
    _WD_Navigate($sSession, "https://maximo-demo76.mro.com/maximo/webclient/login/login.jsp?welcome=true")

    _WD_Window($sSession, "Maximize")

    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Attach($sSession, "https://maximo-demo76.mro.com/maximo/webclient/login/login.jsp?welcome=true", "URL")
    Sleep(2000)

    ;FOR TEST PURPOSES ONLY! USED FOR TESTING BACKGROUND CAPABILITY
    ;_WD_Window($sSession, "Minimize")
    ;Sleep(2000)
EndFunc

Func DemoElements()

    Local $userName = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='username']")
    Local $password = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='password']")
    Local $signIN   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='tiv_btn']")

    _WD_ElementAction($sSession, $userName, 'value', "maximo")
    _WD_ElementAction($sSession, $userName, 'text')
    Sleep(500)
    _WD_ElementAction($sSession, $password, 'value', "maxpass1")
    _WD_ElementAction($sSession, $password, 'text')
    Sleep(500)
    _WD_ElementAction($sSession, $signIN, 'click')
    Sleep(5000)


    ; Search for Work Order Tracking in the Nav bar
    _WD_Window($sSession, "window")
    Local $woTrack   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='nav_search_fld']")
    _WD_ElementAction($sSession, $woTrack, 'value', "work order tracking")
    _WD_ElementAction($sSession, $woTrack, 'text')
    Sleep(2000)

    ; Click on Work Order Tracking in the Nav bar
    Local $woTrack2   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='tamatch']")
    _WD_ElementAction($sSession, $woTrack2, 'click')
    Sleep(2000)

    ; Click on New Work Order
    _WD_Window($sSession, "window")
    Local $newWO   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='toolactions_INSERT-tbb_image']")
    _WD_ElementAction($sSession, $newWO, 'click')
    Sleep(3000)

    ; Send Data to Description
    _WD_Window($sSession, "window")
    Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='mad3161b5-tb2']")
    _WD_ElementAction($sSession, $eDescription, 'value', "Did it really work? Can I run in the background?")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)

    ; Get Work Order Number
    Local $eWorkNumber   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='mad3161b5-tb']")
    ConsoleWrite(@CRLF & @CRLF & "Work Order Number: " & $eWorkNumber & @CRLF & @CRLF)
    _WD_ElementAction($sSession, $eWorkNumber, 'property')
    _WD_ElementAction($sSession, $eWorkNumber, 'text')
    ConsoleWrite(@CRLF & @CRLF & "Work Order Number: " & $eWorkNumber & @CRLF & @CRLF)
    Sleep(500)

    ; Send Location
    _WD_Window($sSession, "window")
    Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='m7b0033b9-tb']")
    _WD_ElementAction($sSession, $eDescription, 'value', "MOFLOOR2")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)

    ; Send Work Type
    _WD_Window($sSession, "window")
    Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='me2096203-tb']")
    _WD_ElementAction($sSession, $eDescription, 'value', "CM")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)

    ; Send Reported By (Mike Small)
    _WD_Window($sSession, "window")
    Local $eReportBy   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='me25d1b3-tb']")
    _WD_ElementAction($sSession, $eReportBy, 'value', "SMALL")
    _WD_ElementAction($sSession, $eReportBy, 'text')
    Sleep(500)

    ; Send Reported By Date
    _WD_Window($sSession, "window")
    Local $eReportDate   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='m972c8009-tb']")
    _WD_ElementAction($sSession, $eReportDate, 'value', "9/10/19 5:15 PM")
    _WD_ElementAction($sSession, $eReportDate, 'text')
    Sleep(500)

    ; Send Phone
    _WD_Window($sSession, "window")
    Local $ePhone   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='ma6bd18c6-tb']")
    _WD_ElementAction($sSession, $ePhone, 'value', "1234")
    _WD_ElementAction($sSession, $ePhone, 'text')
    Sleep(500)

    ; Click Select Owner
    ;_WD_Window($sSession, "window")
    ;Local $eOwnerGroup   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@id='md86fe08f_ns_menu_OWNER_OPTION_a_tnode']")
    ;_WD_ElementAction($sSession, $eOwnerGroup, 'click')
    ;Sleep(2000)

    ; Select Person Group (Mike Wilson)
    ;_WD_Window($sSession, "window")
    ;Local $eMikeWilson   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@id='m2578bad6_tdrow_[C:0]_ttxt-lb[R:1]']")
    ;_WD_ElementAction($sSession, $eMikeWilson, 'click')
    ;Sleep(500)

    ; Click on logout
    _WD_Window($sSession, "window")
    Local $logOut   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@alt='Sign Out ALT+S']")
    _WD_ElementAction($sSession, $logOut, 'click')
    Sleep(1000)

    ; Click on No so it can logout
    _WD_Window($sSession, "window")
    Local $eNo   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='m96ad0396-pb']")
    _WD_ElementAction($sSession, $eNo, 'click')
    Sleep(3000)


    MsgBox("", "test", "Did it work?")
    Sleep(3000)

EndFunc


;*******************************************************************************
; Function Definitions
;*******************************************************************************
Func SetupEdge()
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--verbose')

$sDesiredCapabilities = '{"capabilities":{}}'
EndFunc

if you want to see if you can get it to run in the background and then work on something else while its running un-comment lines 101-103. 

Again most people on this forum are smarter than me so please someone prove me wrong and tell/show me that it is possible to run this script and do work at the same time.  

Link to comment
Share on other sites

7 minutes ago, nooneclose said:

My script can run while minimized but I can not do anything else until its done. (or it won't fully work)

"Doesn't work" isn't sufficient for us to understand the problem. Please provide further details on what exactly doesn't function as expected when the window is minimized and you continue working on your PC.

P.S. Have you considered running in "headless" mode?

Link to comment
Share on other sites

@Danp2 When I run the script while it is minimized and I begin to do other tasks such as, writing to cells in Excel or surf the web in Chome, I check the scripts progress after the message box pops up (it pops up at the very end of the script letting me know its done) and the script will have stoped: before it clicks on logout (90% done),  before it navigated to the demo site (5% done) or some random place in-between. 

I have not tried "headless" mode. What is that? If you think it will work I'm more than willing to try it. just tell me how.

Edited by nooneclose
Link to comment
Share on other sites

This isn't something that I've done myself, so I can't make recommendations. Also can't expect us to debug your script for you. Suggest that you come up with a simple reproducer script that demonstrates the issue.

1 hour ago, nooneclose said:

I have not tried "headless" mode. What is that? If you think it will work I'm more than willing to try it. just tell me how.

Use this forum's search feature or Google to answer this on your own. :rolleyes:

Link to comment
Share on other sites

@Danp2 I ran a lot of tests and it looks like after line 106 executes I am free to do work in the foreground (I opened and filled some Excel cells and then opened Chrome and navigated to the Autoit forms page) while the script was running in the background. (I also had to increase the sleep between clicks for the logout button)

My script works. :D I just had to wait until certain functions executed (the navigation functions I'm pretty sure we're the ones having issues) 

I did not minimize the WebDriver.exe during the successful tests. (minimizing it caused it to stop working immediately sometimes)

Here is the final code that works:

; Required Files for WebDriver to work
#include "wd_core.au3"
#include "wd_helper.au3"
#include <FileConstants.au3>

; Edge (standard)
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--host=127.0.0.1')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c":true, "binary":"' & StringReplace (@UserProfileDir, "\", "/") & '/AppData/Local/Microsoft/Edge SxS/Application/msedge.exe"}}}}'

Local Enum $eFireFox = 0, _
            $eChrome, _
            $eEdge

Local $aDemoSuite[][2] = [["DemoTimeouts", False], _
                         ["DemoNavigation", True], _
                         ["DemoElements", True], _
                         ["DemoScript", False], _
                         ["DemoCookies", False], _
                         ["DemoAlerts", False], _
                         ["DemoFrames", False], _
                         ["DemoActions", False], _
                         ["DemoWindows", False]]

Local Const $sElementSelector = "//input[@name='q']"

Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = $_WD_DEBUG_Info

SetupEdge()

_WD_Startup()


If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error = $_WD_ERROR_Success Then
    For $iIndex = 0 To UBound($aDemoSuite, $UBOUND_ROWS) - 1
        If $aDemoSuite[$iIndex][1] Then
            ConsoleWrite("Running: " & $aDemoSuite[$iIndex][0] & @CRLF)
            Call($aDemoSuite[$iIndex][0])
        Else
            ConsoleWrite("Bypass: " & $aDemoSuite[$iIndex][0] & @CRLF)
        EndIf
    Next
EndIf

_WD_DeleteSession($sSession)
_WD_Shutdown()


If @error <> $_WD_ERROR_Success Then
    Exit -1
EndIf

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error = $_WD_ERROR_Success Then
    For $iIndex = 0 To UBound($aDemoSuite, $UBOUND_ROWS) - 1
        If $aDemoSuite[$iIndex][1] Then
            ConsoleWrite("Running: " & $aDemoSuite[$iIndex][0] & @CRLF)
            Call($aDemoSuite[$iIndex][0])
        Else
            ConsoleWrite("Bypass: " & $aDemoSuite[$iIndex][0] & @CRLF)
        EndIf
    Next
EndIf


;*******************************************************************************
; DEMO Function Definitions
;*******************************************************************************
Func DemoNavigation()
    _WD_Navigate($sSession, "https://maximo-demo76.mro.com/maximo/webclient/login/login.jsp?welcome=true")

    _WD_Window($sSession, "Maximize")

    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Attach($sSession, "https://maximo-demo76.mro.com/maximo/webclient/login/login.jsp?welcome=true", "URL")
    Sleep(2000)

    _WD_Window($sSession, "Minimize")
    Sleep(2000)
EndFunc

Func DemoElements()
    MsgBox("", "Message!", "You may now begin working while the bot runs in the background.")

    Local $userName = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='username']")
    Local $password = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@name='password']")
    Local $signIN   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@class='tiv_btn']")

    _WD_ElementAction($sSession, $userName, 'value', "maximo")
    _WD_ElementAction($sSession, $userName, 'text')
    Sleep(500)
    _WD_ElementAction($sSession, $password, 'value', "maxpass1")
    _WD_ElementAction($sSession, $password, 'text')
    Sleep(500)
    _WD_ElementAction($sSession, $signIN, 'click')
    Sleep(5000)

    ; Search for Work Order Tracking in the Nav bar
    _WD_Window($sSession, "window")
    Local $woTrack   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='nav_search_fld']")
    _WD_ElementAction($sSession, $woTrack, 'value', "work order tracking")
    _WD_ElementAction($sSession, $woTrack, 'text')
    Sleep(2000)

    ; Click on Work Order Tracking in the Nav bar
    Local $woTrack2   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@class='tamatch']")
    _WD_ElementAction($sSession, $woTrack2, 'click')
    Sleep(2000)

    ; Click on New Work Order
    _WD_Window($sSession, "window")
    Local $newWO   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='toolactions_INSERT-tbb_image']")
    _WD_ElementAction($sSession, $newWO, 'click')
    Sleep(3000)

    ; Send Data to Description
    _WD_Window($sSession, "window")
    Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='mad3161b5-tb2']")
    _WD_ElementAction($sSession, $eDescription, 'value', "Did it really work? Can I run in the background?")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)

    ; Get Work Order Number
    Local $eWorkNumber   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='mad3161b5-tb']")
    ConsoleWrite(@CRLF & @CRLF & "Work Order Number: " & $eWorkNumber & @CRLF & @CRLF)
    _WD_ElementAction($sSession, $eWorkNumber, 'property')
    _WD_ElementAction($sSession, $eWorkNumber, 'text')
    ConsoleWrite(@CRLF & @CRLF & "Work Order Number: " & $eWorkNumber & @CRLF & @CRLF)
    Sleep(500)

    ; Send Location
    _WD_Window($sSession, "window")
    Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='m7b0033b9-tb']")
    _WD_ElementAction($sSession, $eDescription, 'value', "MOFLOOR2")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)

    ; Send Work Type
    _WD_Window($sSession, "window")
    Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='me2096203-tb']")
    _WD_ElementAction($sSession, $eDescription, 'value', "CM")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)

    ; Send Reported By (Mike Small)
    _WD_Window($sSession, "window")
    Local $eReportBy   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='me25d1b3-tb']")
    _WD_ElementAction($sSession, $eReportBy, 'value', "SMALL")
    _WD_ElementAction($sSession, $eReportBy, 'text')
    Sleep(500)

    ; Send Reported By Date
    _WD_Window($sSession, "window")
    Local $eReportDate   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='m972c8009-tb']")
    _WD_ElementAction($sSession, $eReportDate, 'value', "9/10/19 5:15 PM")
    _WD_ElementAction($sSession, $eReportDate, 'text')
    Sleep(500)

    ; Send Phone
    _WD_Window($sSession, "window")
    Local $ePhone   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='ma6bd18c6-tb']")
    _WD_ElementAction($sSession, $ePhone, 'value', "1234")
    _WD_ElementAction($sSession, $ePhone, 'text')
    Sleep(500)

    ; Click Select Owner
    ;_WD_Window($sSession, "window")
    ;Local $eOwnerGroup   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@id='md86fe08f_ns_menu_OWNER_OPTION_a_tnode']")
    ;_WD_ElementAction($sSession, $eOwnerGroup, 'click')
    ;Sleep(2000)

    ; Select Person Group (Mike Wilson)
    ;_WD_Window($sSession, "window")
    ;Local $eMikeWilson   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[@id='m2578bad6_tdrow_[C:0]_ttxt-lb[R:1]']")
    ;_WD_ElementAction($sSession, $eMikeWilson, 'click')
    ;Sleep(500)

    ; Click on logout
    _WD_Window($sSession, "window")
    Local $logOut   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@alt='Sign Out ALT+S']")
    _WD_ElementAction($sSession, $logOut, 'click')
    Sleep(3000)

    ; Click on No so it can logout
    _WD_Window($sSession, "window")
    Local $eNo   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='m96ad0396-pb']")
    _WD_ElementAction($sSession, $eNo, 'click')
    Sleep(3000)


    MsgBox("", "test", "Did it work?")
    Sleep(3000)

EndFunc


;*******************************************************************************
; Function Definitions
;*******************************************************************************
Func SetupEdge()
_WD_Option('Driver', 'MicrosoftWebDriver.exe')
_WD_Option('Port', 17556)
_WD_Option('DriverParams', '--verbose')

$sDesiredCapabilities = '{"capabilities":{}}'
EndFunc

I am very happy to see the code running smoothly in the background while giving me the chance to perform work in the foreground.

Thank you @Danp2 for all your hard work in making this UDF possible! this has been a great learning opportunity for me and once again I am amazed at Autoit's potential.  

Link to comment
Share on other sites

44 minutes ago, nooneclose said:

_WD_Window($sSession, "window")

Why do you keep executing this line in multiple places? It shouldn't be necessary, so I'm trying to understand what you are trying to accomplish here.

45 minutes ago, nooneclose said:

I did not minimize the WebDriver.exe during the successful tests. (minimizing it caused it to stop working immediately sometimes)

This console can be completely hidden from the start by adding the following line near the beginning of your script --

$_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error

You can also control the visibility of the console with the function_WD_ConsoleVisible.

Link to comment
Share on other sites

@Danp2 I used _WD_Window($sSession, "window") so many times because I thought it was necessary for the script to work. thank you for telling me otherwise. 

I added the "$_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error" but it didn't close the WebDriver.exe. Then when I went to look up info in the wd_core I didn't find any info on _wd_ConsoleVisible other than a note saying you added it?  

Random question: How do I get the value of an input field in WebDriver?  I tried this:

; Get Work Order Number
Local $eWorkNumber   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='mad3161b5-tb']")
ConsoleWrite(@CRLF & @CRLF & "Work Order Number: " & $eWorkNumber & @CRLF & @CRLF)
_WD_ElementAction($sSession, $eWorkNumber, 'property')
_WD_ElementAction($sSession, $eWorkNumber, 'text')
ConsoleWrite(@CRLF & @CRLF & "Work Order Number: " & $eWorkNumber & @CRLF & @CRLF)
Sleep(500)

but it doesn't get me the number value it gets me some random string of numbers and letters.

It should get me "1234" but it gets me "0005e6cf-da10-4c49-8747-448deb99f78a" 

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