Jump to content

WebDriver UDF - Help & Support (IV)


Recommended Posts

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

Link to comment
Share on other sites

@Danp2
 

How can I click this checkbox
image.thumb.png.46c24d8ee6bd40bfc635c9f5ee7c844f.png

here is my code


 

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

Local $sCapabilities, $sSession
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
;~     _WD_CapabilitiesAdd('args', '--headless')
    _WD_CapabilitiesDump(@ScriptLineNumber) ; dump current Capabilities setting to console - only for testing in this demo
    Local $sCapabilities = _WD_CapabilitiesGet()
_WD_Startup()
$sSession = _WD_CreateSession($sCapabilities)
_WD_Navigate($sSession, "chrome://settings/clearBrowserData")
_WD_LoadWait($sSession, 2000)
_WD_ElementAction($sSession, _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, '//*[@id="label"]'), 'click')


Log
_WD_CreateSession ==> Success [0] : 92fbf75e9c653f1b615fe7dcbbec1eb0
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Navigate ==> Success [0] : Parameters:   URL=chrome://settings/clearBrowserData
__WD_Post ==> No match [8] : HTTP status = 404
_WD_FindElement ==> No match [8] : Parameters:   Strategy=xpath   Selector=//*[@id="label"]   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> No match [8] : HTTP status = 404
_WD_ElementAction ==> No match [8] : Parameters:   Command=click   Option=Default

 

Link to comment
Share on other sites

I have to "Logout" from my Salaty-Application over a pull-down-menu.

The logout-link (red circle in picture in the bottom) titeled "Abmelden" I can click with:

 

$sLink = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@href='/auth/cloudid/logout']")

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

out of problems, if it is visible !!!   Otherwise not !!!   I tried it manytimes manually.

To get it visible I need a mouse-over or mouse-hover over the people-symbol (yellow circle)

The menu looks in HTML:
 

<nav id="user-menu">
    <div class="profile-menu">
            <span class="fa fa-user"></span>
            <ul>
                <li id="spacing-username">
                    <p><strong>Benutzername: </strong><a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="aac6c5c2c4eadecbc3ccdfc487cec3cfc4d9decf84cecf">[email&#160;protected]</a></p>
                </li>
                <li>
                    <p><strong>Abrechnungsmonat: </strong>August 2022</p>
                </li>
                                <li class="alternate-separator">    
                </li>
                <li class="alternate">
                    <a href="/users/edit" data-target onclick="spinner.show('Lade Benutzerdaten ..')"><strong>Benutzerdaten ändern</strong></a>
                </li>
                                    <li class="alternate">
                        <a href="/servicewelt/kaufservice/redirect" target="_blank" data-target><strong>Zum Bestellservice</strong></a>
                    </li>
                    <li class="alternate">
                        <a href="/customers/edit" data-target onclick="spinner.show('Lade Rechnungsdaten ..')"><strong>Zahlungs- und Rechnungsdaten</strong></a>
                    </li>
                    <li class="alternate">
                        <a href="/customers/invoices" data-target onclick="spinner.show('Lade Rechnungen ..')"><strong>Rechnungen</strong></a>
                    </li>
                
                <li id="spacing-logout">
                    <a href=/auth/cloudid/logout data-target onclick="spinner.show('Logout ..')"><strong>Abmelden</strong></a>
                </li>
            </ul>
    </div>
</nav>

How I have to set the mouse-over or mouse-hover to the people-symbol ?

The mouse-pointer must still stay over the people-symbol up to execute the click-command on the "red circle" !

Thanks and regards

LogOut02.png

Edited by Hamburgo
Link to comment
Share on other sites

@BuiTuanAnhThat page uses complex objects with shadow roots. I don't have the time to figure this out for you, but perhaps someone else will offer some help. If you search the forum on the term "_WD_GetShadowRoot", you should be able to locate some recent discussions that may be helpful.

Alternatively, you may want to research to see if the task of clearing browser data can be accomplished using Javascript and _WD_ExecuteScript.

P.S. Your post was moved here by one of the friendly mods. Please post here in the future instead of the thread in the Examples section. 😉

Link to comment
Share on other sites

Today I try to update the geckodriver from version 23.0 (dated May 2019)

to the current version 31.0.

I did not change anything in my scripts.

After the start of my webdriver session I a error message as follow:

1660369297755   geckodriver     INFO    Listening on 127.0.0.1:4444
1660369298071   webdriver::server       WARN    Rejected POST request with disallowed content type application/x-www-form-urlencoded

 

and nothing more will be happen.

What can be the problem ?

Link to comment
Share on other sites

@HamburgoThere were security fixes applied in Geckodriver to avoid a RCE situation. You can read more about it here.

You've provided very little details, so it's difficult to know how to guide you from here. I suspect the issue is with your Capabilities JSON string that is passed to _WD_CreateSession. Please post the contents of this string here. Also, make sure you are running the latest version of the Webdriver UDF.

Regards,

Dan

Link to comment
Share on other sites

  This is may string:

$sDesiredCapabilities = '{"capabilities":{"alwaysMatch": {"moz:firefoxOptions": {"args": ["-profile", "' & GetFFProfileByName() & '"],"log": {"level": "trace"}}}}}'
  

Func GetFFProfileByName($Name="WebDriver")
    Local $sDefault, $sProfilePath = ''

    Local $sProfilesPath = StringReplace(@AppDataDir, '\', '/') & "/Mozilla/Firefox/"
    Local $sFilename = $sProfilesPath & "profiles.ini"
    Local $aSections = IniReadSectionNames ($sFilename)
;   _ArrayDisplay($aSections, "INI-Sections")

    If Not @error Then
        For $i = 1 To $aSections[0]
            $sName = IniRead($sFilename, $aSections[$i], 'Name', '0')

            If $sName = $Name Then
                $sProfilePath = $sProfilesPath & IniRead($sFilename, $aSections[$i], "Path", "")
                ExitLoop
            EndIf
        Next
    EndIf

    Return $sProfilePath
 EndFunc

The problem will be that I do not running the lastest Webdriver UDF, because I am not sure, that my scripts will run on this out of problems.

Link to comment
Share on other sites

2 hours ago, Hamburgo said:

The problem will be that I do not running the lastest Webdriver UDF, because I am not sure, that my scripts will run on this out of problems.

Give it a chance.

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

Link to comment
Share on other sites

I'm trying to connect to an existing Chrome process to control it. I think I've found most of the code here:

As recommended from:

 

I've launched Chrome with --remote-debugging-port=9222 and chose [NO] to try to connect to the existing instance, however it still opens a new Chrome Window instead of Navigating the existing one. No code from the example has been modified and Chrome is up to date. The log output is:

_WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 104.0.5112.79 : DriverLatest = 104.0.5112.79
_WD_Option ==> Success [0] : Parameters:   Option=Driver   Value=chromedriver.exe
_WD_Option ==> Success [0] : Parameters:   Option=Port   Value=9515
_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--log trace
_WD_CapabilitiesAdd ==> Success [0] : Successfully used [firstMatch]  with specified browser: chrome
_WD_CapabilitiesAdd ==> Browser or feature not supported [19] : Not supported KEY parameter ( must be defined in $_WD_KEYS__*** ).      $key = goog:chromeOptions     $value1 = w3c     $value2 = True
_WD_CapabilitiesAdd ==> Browser or feature not supported [19] : Not supported KEY parameter ( must be defined in $_WD_KEYS__*** ).      $key = goog:chromeOptions     $value1 = debuggerAddress     $value2 = localhost:9222
_WD_CapabilitiesDump: JSON structure starts below: 88 :WebDriver:Capabilities:
{
    "capabilities":{}
}
_WD_CapabilitiesDump: JSON structure ends above.
_WD_IsLatestRelease ==> Success [0] : True
_WD_Startup: OS:    WIN_10 WIN32_NT 19044 
_WD_Startup: AutoIt:    3.3.16.0
_WD_Startup: Webdriver UDF: 0.10.1 (Up to date)
_WD_Startup: WinHTTP:   1.6.4.2
_WD_Startup: Driver:    chromedriver.exe (32 Bit)
_WD_Startup: Params:    --log trace
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe" --log trace 
_WD_Startup ==> Success [0]
__WD_Post ==> Success [0] : HTTP status = 200
_WD_CreateSession ==> Success [0] : 23eadf2d8c0188b14c02a168a90c4146
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Navigate ==> Success [0] : Parameters:   URL=https://www.google.com/
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Navigate ==> Success [0] : Parameters:   URL=https://www.autoitscript.com/forum
__WD_Delete ==> Success [0] : HTTP status = 200
_WD_DeleteSession ==> Success [0] : WebDriver session deleted

 

I've also tried to modify the code from here:


As recommended in the FAQ. My code is as such:
 

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

# HOW TO TEST:
; At first run choose [Yes] to create new session FireFox running instance
; At second run choose [No] to attach to active FireFox running instance

# TODO:
; https://github.com/operasoftware/operachromiumdriver/blob/master/docs/desktop.md   --remote-debugging-port=port

Global $_MY__WD_SESSION
Global $__g_sDownloadDir = @ScriptDir & '\Testing_Download'

_Test()

Exit

Func _Test()
    Local $s_FireFox_Binary = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe"
    If $s_FireFox_Binary And FileExists($s_FireFox_Binary) = 0 Then $s_FireFox_Binary = ''

    Local $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", _
            "Open new sesion ?" & @CRLF & "[ NO ] = Try attach to active Chrome.exe instance")
    If $iAnswer = $IDYES Then
        _Testing_CreateSession($s_FireFox_Binary)
;~      _Testing_WD_Navigate()
        Return     ; do not process next functions
    Else
        _Testing_AttachSession($s_FireFox_Binary)
        _WD_Navigate($_MY__WD_SESSION, 'https://www.google.com/')
    EndIf

    $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", _
            "Do you want to test ?" & @CRLF & "[ NO ] = Refresh - prevent expiration")
    If $iAnswer = $IDYES Then
        _Testing_WD_Navigate()
    Else
        _Testing_Refreshing()
    EndIf

    ; CleanUp
    _WD_DeleteSession($_MY__WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Test

Func _Testing_CreateSession($s_FireFox_Binary)
    $_MY__WD_SESSION = _MY__WD_SetupFireFox(False, $__g_sDownloadDir, $s_FireFox_Binary, False)
EndFunc   ;==>_Testing_CreateSession

Func _Testing_AttachSession($s_FireFox_Binary)
    $_MY__WD_SESSION = _MY__WD_SetupFireFox(False, $__g_sDownloadDir, $s_FireFox_Binary, True)
EndFunc   ;==>_Testing_AttachSession

Func _Testing_Refreshing()
    While 1
;~      _WD_Navigate($_MY__WD_SESSION, '')
        _WD_Action($_MY__WD_SESSION, 'REFRESH')
        Local $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", "Finish refreshing?" & @CRLF & "[No] = Refresh - prevent expiration", 60)
        If $iAnswer = $IDYES Then Return
    WEnd
EndFunc   ;==>_Testing_Refreshing

Func _MY__WD_SetupFireFox($b_Headless, $s_Download_dir = Default, $s_FireFox_Binary = Default, $bTryAttach = False)
    If $s_Download_dir = Default Then
        $s_Download_dir = ''
    ElseIf $s_Download_dir Then
        If FileExists($s_Download_dir) = 0 Then $s_Download_dir = ''
    EndIf

    Local $s_Capabilities = Default
    Local $s_Profile_Dir  = @LocalAppDataDir & '\Google\Chrome\Profiles\WD_Testing_Profile'
    DirCreate($s_Download_dir) ; MUST EXIST !!
    DirCreate($s_Profile_Dir) ; MUST EXIST !!

    _WD_UpdateDriver('chrome')
    If @error Then Return SetError(@error, @extended, '')

    #WARRNING DO NOT USE '--log-path=' BECAUSE OF   RODO / GDPR
    _WD_Option('Driver', 'chromedriver.exe')
    ;_WD_Option('Port', 9222)
    _WD_Option('Port', 9515)
    _WD_Option('DefaultTimeout', 1000)

    If $bTryAttach Then
        _WD_CapabilitiesAdd('goog:chromeOptions', 'debuggerAddress', 'localhost:9222')
    Else
        _WD_Option('DriverParams', '--log trace --marionette-port 2828')

        _WD_CapabilitiesStartup()
        _WD_CapabilitiesAdd('alwaysMatch')
        _WD_CapabilitiesAdd('acceptInsecureCerts', True)
        _WD_CapabilitiesAdd('firstMatch', 'Chrome')
        _WD_CapabilitiesAdd('args', '-profile')

        _WD_CapabilitiesAdd('args', $s_Profile_Dir) ; CHANGE TO PROPER DIRECTORY PATH
        If $s_FireFox_Binary Then _WD_CapabilitiesAdd('binary', $s_FireFox_Binary)

        If $b_Headless Then _
                _WD_CapabilitiesAdd('args', '--headless')

        _WD_CapabilitiesDump(@ScriptLineNumber & ' :WebDriver:Capabilities:')
        $s_Capabilities = _WD_CapabilitiesGet()
    EndIf

    _WD_Startup()
    If @error Then Return SetError(@error, @extended, '')

    Local $WD_SESSION = _WD_CreateSession($s_Capabilities)
    Return SetError(@error, @extended, $WD_SESSION)
EndFunc   ;==>_MY__WD_SetupFireFox

Func _Testing_WD_Navigate()
    _WD_Navigate($_MY__WD_SESSION, 'https://www.autoitscript.com/forum')
EndFunc   ;==>_Testing_WD_Navigate

 

Am I doing something wrong?

 

Also, is there a way to set Chrome (and MSEdge) to always launch with remote debugging by default?

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

1 hour ago, rcmaehl said:

_WD_CapabilitiesAdd ==> Browser or feature not supported [19] : Not supported KEY parameter ( must be defined in $_WD_KEYS__*** ).      $key = goog:chromeOptions     $value1 = w3c     $value2 = True

_WD_CapabilitiesAdd ==> Browser or feature not supported [19] : Not supported KEY parameter ( must be defined in $_WD_KEYS__*** ).      $key = goog:chromeOptions     $value1 = debuggerAddress     $value2 = localhost:9222

This is telling you that something is wrong with your usage of _WD_CapabilitiesAdd. Looking at your code, I don't even see anything related to "w3c". For the second line, I believe the correct usage would be --

_WD_CapabilitiesAdd('debuggerAddress', 'localhost:9222')

 

Link to comment
Share on other sites

1 hour ago, Danp2 said:

This is telling you that something is wrong with your usage of _WD_CapabilitiesAdd. Looking at your code, I don't even see anything related to "w3c". For the second line, I believe the correct usage would be --

_WD_CapabilitiesAdd('debuggerAddress', 'localhost:9222')

 

Okay:

I've tried both the following code and they both return

_WD_Startup ==> Success [0]
__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_CreateSession ==> Webdriver Exception [10]

I've also tried _WD_Option('Port', 9515), as found in some of the example scripts but that just hangs before giving the same error.

I've dug through and it looks like this is a WinHTTP error from _WinHttpSimpleRequest but I don't see a value of 6 as a valid $iErr?

 

Try 1

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

# HOW TO TEST:
; At first run choose [Yes] to create new session Chrome running instance
; At second run choose [No] to attach to active Chrome running instance

# TODO:
; https://github.com/operasoftware/operachromiumdriver/blob/master/docs/desktop.md   --remote-debugging-port=port

Global $_MY__WD_SESSION
Global $__g_sDownloadDir = ""

_Test()

Exit

Func _Test()
    Local $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", _
            "Open new sesion ?" & @CRLF & "[ NO ] = Try attach to active Chrome instance")
    If $iAnswer = $IDYES Then
        _Testing_CreateSession()
        Return     ; do not process next functions
    Else
        _Testing_AttachSession()
        _WD_Navigate($_MY__WD_SESSION, 'https://www.google.com/')
    EndIf

    $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", _
            "Do you want to test ?" & @CRLF & "[ NO ] = Refresh - prevent expiration")
    If $iAnswer = $IDYES Then
        _Testing_WD_Navigate()
    Else
        _Testing_Refreshing()
    EndIf

    ; CleanUp
    _WD_DeleteSession($_MY__WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Test

Func _Testing_CreateSession()
    $_MY__WD_SESSION = _MY__WD_SetupChrome(False, $__g_sDownloadDir, False)
EndFunc   ;==>_Testing_CreateSession

Func _Testing_AttachSession()
    $_MY__WD_SESSION = _MY__WD_SetupChrome(False, $__g_sDownloadDir, True)
EndFunc   ;==>_Testing_AttachSession

Func _Testing_Refreshing()
    While 1
;~      _WD_Navigate($_MY__WD_SESSION, '')
        _WD_Action($_MY__WD_SESSION, 'REFRESH')
        Local $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", "Finish refreshing?" & @CRLF & "[No] = Refresh - prevent expiration", 60)
        If $iAnswer = $IDYES Then Return
    WEnd
EndFunc   ;==>_Testing_Refreshing

Func _Testing_WD_Navigate()
    _WD_Navigate($_MY__WD_SESSION, 'https://www.autoitscript.com/forum')
EndFunc   ;==>_Testing_WD_Navigate

Func _MY__WD_SetupChrome($b_Headless, $s_Download_dir = Default, $bTryAttach = False)
    If $s_Download_dir = Default Then
        $s_Download_dir = ''
    ElseIf $s_Download_dir Then
        If FileExists($s_Download_dir) = 0 Then $s_Download_dir = ''
    EndIf

    _WD_UpdateDriver('chrome')
    If @error Then Return SetError(@error, @extended, '')

    _WD_Option('Driver', 'chromedriver.exe')
    ;_WD_Option('Port', 9515)
    _WD_Option('Port', 9222)
    _WD_CapabilitiesStartup()
    Local $s_AttachOption = (($bTryAttach) ? ("") : (" --remote-debugging-port=9222"))
    _WD_Option('DriverParams', '--log trace' & $s_AttachOption)
    _WD_CapabilitiesAdd('firstMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('debuggerAddress', 'localhost:9222')

    If $bTryAttach Then _
            _WD_CapabilitiesAdd('debuggerAddress', 'localhost:9222')
    If $b_Headless Then _
            _WD_CapabilitiesAdd('args', '--headless')
    If $s_Download_dir Then _
            _WD_CapabilitiesAdd('prefs', 'download.default_directory', $s_Download_dir)

    _WD_CapabilitiesDump(@ScriptLineNumber & ' :WebDriver:Capabilities:')

    _WD_Startup()
    If @error Then Return SetError(@error, @extended, '')

    Local $s_Capabilities = _WD_CapabilitiesGet()
    Local $WD_SESSION = _WD_CreateSession($s_Capabilities)
    Return SetError(@error, @extended, $WD_SESSION)
EndFunc   ;==>_MY__WD_SetupChrome


Try 2

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

# HOW TO TEST:
; At first run choose [Yes] to create new session FireFox running instance
; At second run choose [No] to attach to active FireFox running instance

# TODO:
; https://github.com/operasoftware/operachromiumdriver/blob/master/docs/desktop.md   --remote-debugging-port=port

Global $_MY__WD_SESSION
Global $__g_sDownloadDir = @ScriptDir & '\Testing_Download'

_Test()

Exit

Func _Test()
    Local $s_FireFox_Binary = "C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe"
    If $s_FireFox_Binary And FileExists($s_FireFox_Binary) = 0 Then $s_FireFox_Binary = ''

    Local $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", _
            "Open new sesion ?" & @CRLF & "[ NO ] = Try attach to active Chrome.exe instance")
    If $iAnswer = $IDYES Then
        _Testing_CreateSession($s_FireFox_Binary)
;~      _Testing_WD_Navigate()
        Return     ; do not process next functions
    Else
        _Testing_AttachSession($s_FireFox_Binary)
        _WD_Navigate($_MY__WD_SESSION, 'https://www.google.com/')
    EndIf

    $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", _
            "Do you want to test ?" & @CRLF & "[ NO ] = Refresh - prevent expiration")
    If $iAnswer = $IDYES Then
        _Testing_WD_Navigate()
    Else
        _Testing_Refreshing()
    EndIf

    ; CleanUp
    _WD_DeleteSession($_MY__WD_SESSION)
    _WD_Shutdown()
EndFunc   ;==>_Test

Func _Testing_CreateSession($s_FireFox_Binary)
    $_MY__WD_SESSION = _MY__WD_SetupFireFox(False, $__g_sDownloadDir, $s_FireFox_Binary, False)
EndFunc   ;==>_Testing_CreateSession

Func _Testing_AttachSession($s_FireFox_Binary)
    $_MY__WD_SESSION = _MY__WD_SetupFireFox(False, $__g_sDownloadDir, $s_FireFox_Binary, True)
EndFunc   ;==>_Testing_AttachSession

Func _Testing_Refreshing()
    While 1
;~      _WD_Navigate($_MY__WD_SESSION, '')
        _WD_Action($_MY__WD_SESSION, 'REFRESH')
        Local $iAnswer = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON2, "Question", "Finish refreshing?" & @CRLF & "[No] = Refresh - prevent expiration", 60)
        If $iAnswer = $IDYES Then Return
    WEnd
EndFunc   ;==>_Testing_Refreshing

Func _MY__WD_SetupFireFox($b_Headless, $s_Download_dir = Default, $s_FireFox_Binary = Default, $bTryAttach = False)
    If $s_Download_dir = Default Then
        $s_Download_dir = ''
    ElseIf $s_Download_dir Then
        If FileExists($s_Download_dir) = 0 Then $s_Download_dir = ''
    EndIf

    Local $s_Capabilities = Default
    Local $s_Profile_Dir  = @LocalAppDataDir & '\Google\Chrome\Profiles\WD_Testing_Profile'
    DirCreate($s_Download_dir) ; MUST EXIST !!
    DirCreate($s_Profile_Dir) ; MUST EXIST !!

    _WD_UpdateDriver('chrome')
    If @error Then Return SetError(@error, @extended, '')

    #WARRNING DO NOT USE '--log-path=' BECAUSE OF   RODO / GDPR
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9222)
    ;_WD_Option('Port', 9515)
    _WD_Option('DefaultTimeout', 1000)

    If $bTryAttach Then
        _WD_CapabilitiesStartup()
        _WD_CapabilitiesAdd('firstMatch', 'Chrome')
        _WD_CapabilitiesAdd('debuggerAddress', 'localhost:9222')
        _WD_CapabilitiesAdd('w3c', True)
    Else
        _WD_Option('DriverParams', '--log trace --marionette-port 2828')

        _WD_CapabilitiesStartup()
        _WD_CapabilitiesAdd('firstMatch', 'Chrome')
        _WD_CapabilitiesAdd('alwaysMatch')
        _WD_CapabilitiesAdd('acceptInsecureCerts', True)
        _WD_CapabilitiesAdd('firstMatch', 'Chrome')
        _WD_CapabilitiesAdd('args', '-profile')

        _WD_CapabilitiesAdd('args', $s_Profile_Dir) ; CHANGE TO PROPER DIRECTORY PATH
        If $s_FireFox_Binary Then _WD_CapabilitiesAdd('binary', $s_FireFox_Binary)

        If $b_Headless Then _
                _WD_CapabilitiesAdd('args', '--headless')

        _WD_CapabilitiesDump(@ScriptLineNumber & ' :WebDriver:Capabilities:')
        $s_Capabilities = _WD_CapabilitiesGet()
    EndIf

    _WD_Startup()
    If @error Then Return SetError(@error, @extended, '')

    Local $WD_SESSION = _WD_CreateSession($s_Capabilities)
    Return SetError(@error, @extended, $WD_SESSION)
EndFunc   ;==>_MY__WD_SetupFireFox

Func _Testing_WD_Navigate()
    _WD_Navigate($_MY__WD_SESSION, 'https://www.autoitscript.com/forum')
EndFunc   ;==>_Testing_WD_Navigate

 

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

@Danp2:

Ok, I do the update to the current version of Webdriver UDF and after that the session starts successfully.
 

But now I get other problems, that I do not have with the old version (0.1.0.17) of the driver.

The first one I was be able to fix it. :))

Edited by Hamburgo
Link to comment
Share on other sites

@rcmaehlI don't have time to decipher / debug your examples. Here's a simple proof of concept to show that it works --

#include "wd_core.au3"

Global $sDesiredCapabilities, $sSession

ShellExecute("C:\Program Files\Google\Chrome\Application\chrome.exe", "--remote-debugging-port=9222")

SetupChrome()
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "http://yahoo.com")

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": {"debuggerAddress": "localhost:9222"}}}}'
EndFunc

 

Link to comment
Share on other sites

1 hour ago, Danp2 said:

@rcmaehlI don't have time to decipher / debug your examples. Here's a simple proof of concept to show that it works --

 

This also gives the same error on my system so I'm assuming that there's something wrong on my PC.

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...