Jump to content

Recommended Posts

Posted (edited)

I am using webdriver udf using IEDriverServer in msedge browser. Script is running fine in RDP session while logged in the server, but it  stopped working at login page when i run RDP in disconnected mode(not signed out just close the RDP session) scheduled in task scheduler

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




$_WD_DEBUG = $_WD_DEBUG_None ; Could also use $_WD_DEBUG_Error
$_WD_DEBUG = $_WD_DEBUG_Info ; Gives you the greatest level of details
_WD_Option('console', @ScriptDir & "\wdudf.log")

Local $sSession, $sElement,$sCapabilities,$bHeadless

Local $sCapabilities = SetupEdgeIEMode($bHeadless)

_WD_Startup()
 $sSession = _WD_CreateSession($sCapabilities)

_WD_Navigate($sSession, "URL")
   _WD_Window($sSession,"maximize")

_WD_LoadWait($sSession)



$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='unamebean']")

_WD_SetElementValue($sSession,$sElement,"username")
Sleep(2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='pwdbean']")

_WD_SetElementValue($sSession,$sElement,"password")
Sleep(2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='SubmitButton']")

_WD_ElementAction($sSession,$sElement,'click')


_WD_DeleteSession($sSession)
_WD_Shutdown()

Func SetupEdgeIEMode($bHeadless) ; this is for MS Edge IE Mode
    
    Local $sTimeStamp = @YEAR & '-' & @MON & '-' & @MDAY & '_' & @HOUR & @MIN & @SEC
    _WD_Option('Driver', 'IEDriverServer.exe') ;
    

    ;_WD_Option('Port', _WD_GetFreePort(5555, 5600))
    Local $iPort = _WD_GetFreePort(5555, 5600)
    If @error Then Return SetError(@error, @extended, 0)
    _WD_Option('Port', $iPort)
    _WD_Option('DriverParams', '-log-file="' & @ScriptDir & '\log\' & $sTimeStamp & '_WebDriver_EdgeIEMode.log" -log-level=INFO' & " -port=" & $_WD_PORT & " -host=127.0.0.1")
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'msedgeie')
    _WD_CapabilitiesAdd('w3c', True)
    Local $sPath = _WD_GetBrowserPath("msedge.exe")
    If $sPath Then _WD_CapabilitiesAdd("ie.edgepath", $sPath)
    _WD_CapabilitiesAdd("ie.edgechromium", True)
    _WD_CapabilitiesAdd("ignoreProtectedModeSettings", True)
    _WD_CapabilitiesAdd("initialBrowserUrl", "URL")
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless' , '--allow-running-insecure-content')
    _WD_CapabilitiesDump(@ScriptLineNumber)
    Local $sCapabilities = _WD_CapabilitiesGet()
    Return $sCapabilities
EndFunc   ;==>SetupEdgeIEMode

. I am running other scripts too with msedge driver but no issue. It seems IEDriverserver.exe is not interacting with session in disconnect mode(not signed out just close the RDP session).

 

Logs:

 

_WD_Option ==> Success [0] : Parameters:   Option=console   Value=E:\AutoIT\AutoITScripts\wdudf.log
_WD_Option ==> Success [0] : Parameters:   Option=Driver   Value=E:\AutoIT\AutoITScripts\IEDriverServer.exe
_WD_GetFreePort ==> Success [0 / 5555] : Parameters:   MinPort=5555   MaxPort=5600
_WD_Option ==> Success [0] : Parameters:   Option=Port   Value=5555
_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--port=5555 -host=127.0.0.1 -log-file="E:\AutoIT\AutoITScripts\log\2024-11-21_161001_WebDriver_EdgeIEMode.log" -log-level=INFO
_WD_CapabilitiesAdd ==> Success [0] : Successfully used [alwaysMatch]  with specified browser: msedgeie
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_GetBrowserPath ==> Success [0 / 3] : Parameters:    Browser=msedge
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesDump: JSON structure starts below: -1
{
    "capabilities":{
        "alwaysMatch":{
            "se:ieOptions":{
                "w3c":true,
                "ie.edgepath":"C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe",
                "ie.edgechromium":true,
                "ignoreProtectedModeSettings":true,
                "initialBrowserUrl":"https:\/\/url.com",
                "excludeSwitches":[
                    "enable-automation"
                ]
            }
        }
    }
}
_WD_CapabilitiesDump: JSON structure ends above.
_WD_GetFreePort ==> Success [0 / 5555] : Parameters:   MinPort=5555   MaxPort=Default
_WD_IsLatestRelease ==> Success [0] : True
_WD_Startup: OS:    WIN_2016 X64 17763 
_WD_Startup: AutoIt:    3.3.14.5
_WD_Startup: Webdriver UDF:    1.4.0 (Up to date)
_WD_Startup: WinHTTP:    1.6.4.2
_WD_Startup: Driver:    E:\AutoIT\AutoITScripts\IEDriverServer.exe (32 Bit)
_WD_Startup: Params:    --port=5555 -host=127.0.0.1 -log-file="E:\AutoIT\AutoITScripts\log\2024-11-21_161001_WebDriver_EdgeIEMode.log" -log-level=INFO
_WD_Startup: Port:    5555
_WD_Startup: Command:    "E:\AutoIT\AutoITScripts\IEDriverServer.exe" --port=5555 -host=127.0.0.1 -log-file="E:\AutoIT\AutoITScripts\log\2024-11-21_161001_WebDriver_EdgeIEMode.log" -log-level=INFO 
_WD_Startup ==> Success [0]
__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_CreateSession ==> Webdriver Exception [10]
__WD_Post ==> Unknown Command [18] : HTTP status = 404
_WD_FindElement ==> Unknown Command [18] : Parameters:   Strategy=xpath   Selector=//input[@id='unamebean']   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Get ==> Invalid session ID [16] : HTTP status = 404

Edited by MRAJ
  • MRAJ changed the title to Script not working in RDP Closed session
  • 2 weeks later...
Posted

The way you are using the WebDriver, your script requires a full user session. I would say that what you are describing is completely normal with a disconnected RDP session.

One possible solution would be to run your script in headless mode - this should work without a graphical user session.

If that's not enough, you could create a dedicated user for your programme and run it as a Windows service. This way, the script runs in the background and does not need to be actively monitored.

Translated with DeepL.com (free version)

Posted

As you can see in the script i have added headless mode

Local $sSession, $sElement,$sCapabilities,$bHeadless

Local $sCapabilities = SetupEdgeIEMode($bHeadless)
If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless' , '--allow-running-insecure-content')
  • 2 weeks later...
Posted (edited)
On 12/3/2024 at 5:41 PM, MRAJ said:

As you can see in the script i have added headless mode

Local $sSession, $sElement,$sCapabilities,$bHeadless

Local $sCapabilities = SetupEdgeIEMode($bHeadless)

Short answer: Unset value = null value = false.

And no, you not used it, the more not added.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

Short answer: Unset value = null value = false.

And no, you not used it, the more not added.

I didn't get the above. Could you explain little more 

Posted
4 hours ago, MRAJ said:

Could you explain little more 

Just a question: where you set this variable to True ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

Do you mean to add True as below script:

If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless' , True)

Func SetupEdgeIEMode($bHeadless) ; this is for MS Edge IE Mode
    
    Local $sTimeStamp = @YEAR & '-' & @MON & '-' & @MDAY & '_' & @HOUR & @MIN & @SEC
    _WD_Option('Driver', 'IEDriverServer.exe') ;
    

    ;_WD_Option('Port', _WD_GetFreePort(5555, 5600))
    Local $iPort = _WD_GetFreePort(5555, 5600)
    If @error Then Return SetError(@error, @extended, 0)
    _WD_Option('Port', $iPort)
    _WD_Option('DriverParams', '-log-file="' & @ScriptDir & '\log\' & $sTimeStamp & '_WebDriver_EdgeIEMode.log" -log-level=INFO' & " -port=" & $_WD_PORT & " -host=127.0.0.1")
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'msedgeie')
    _WD_CapabilitiesAdd('w3c', True)
    Local $sPath = _WD_GetBrowserPath("msedge.exe")
    If $sPath Then _WD_CapabilitiesAdd("ie.edgepath", $sPath)
    _WD_CapabilitiesAdd("ie.edgechromium", True)
    _WD_CapabilitiesAdd("ignoreProtectedModeSettings", True)
    _WD_CapabilitiesAdd("initialBrowserUrl", "URL")
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')

If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless' , True)--->>>> do need to add this line

    _WD_CapabilitiesDump(@ScriptLineNumber)
    Local $sCapabilities = _WD_CapabilitiesGet()
    Return $sCapabilities
EndFunc   ;==>SetupEdgeIEMode
Posted

What mLipok was trying to say, is that you only declare $bHeadless, but you never set it to True, so when you run

SetupEdgeIEMode( $bHeadless )

It's actually running SetupEdgeIEMode ( false )

Well, from my own experience, running the script with the old IE will have strange behaviors when RDP was disconnected.

The new MS Edge might have fixed those problems, after all it's just another Chromium underneath, but Google Chrome gave me plenty of troubles. Only Firefox seems to be stable and work most of the time for Web Driver.

Posted

 

Local $sSession, $sElement,$sCapabilities,$bHeadless

Local $sCapabilities = SetupEdgeIEMode()

_WD_Startup()
 $sSession = _WD_CreateSession($sCapabilities)

_WD_Navigate($sSession, "URL")
   _WD_Window($sSession,"maximize")

_WD_LoadWait($sSession)



$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='unamebean']")

_WD_SetElementValue($sSession,$sElement,"username")
Sleep(2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='pwdbean']")

_WD_SetElementValue($sSession,$sElement,"password")
Sleep(2000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='SubmitButton']")

_WD_ElementAction($sSession,$sElement,'click')


_WD_DeleteSession($sSession)
_WD_Shutdown()

Func SetupEdgeIEMode() ; this is for MS Edge IE Mode
    
    Local $sTimeStamp = @YEAR & '-' & @MON & '-' & @MDAY & '_' & @HOUR & @MIN & @SEC
    _WD_Option('Driver', 'IEDriverServer.exe') ;
    

    ;_WD_Option('Port', _WD_GetFreePort(5555, 5600))
    Local $iPort = _WD_GetFreePort(5555, 5600)
    If @error Then Return SetError(@error, @extended, 0)
    _WD_Option('Port', $iPort)
    _WD_Option('DriverParams', '-log-file="' & @ScriptDir & '\log\' & $sTimeStamp & '_WebDriver_EdgeIEMode.log" -log-level=INFO' & " -port=" & $_WD_PORT & " -host=127.0.0.1")
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'msedgeie')
    _WD_CapabilitiesAdd('w3c', True)
    Local $sPath = _WD_GetBrowserPath("msedge.exe")
    If $sPath Then _WD_CapabilitiesAdd("ie.edgepath", $sPath)
    _WD_CapabilitiesAdd("ie.edgechromium", True)
    _WD_CapabilitiesAdd("ignoreProtectedModeSettings", True)
    _WD_CapabilitiesAdd("initialBrowserUrl", "URL")
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless' , '--allow-running-insecure-content')
    _WD_CapabilitiesDump(@ScriptLineNumber)
    Local $sCapabilities = _WD_CapabilitiesGet()
    Return $sCapabilities
EndFunc   ;==>SetupEdgeIEMode

I tried with above script by removing the $bHeadless under Local $sCapabilities = SetupEdgeIEMode() & Func SetupEdgeIEMode(). But same i am getting it is running but element filling not doing and not interacting.

As this website only runs under EdgeIE mode. When i directly running the website in edge browser it will show me as 

image.png.13a4a2a4b70749d6ebb361e4b0d6fa0f.png

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