Jump to content

WebDriver UDF (W3C compliant version) - 2024/09/21


Danp2
 Share

Recommended Posts

  • 2 weeks later...

FYI.  It appears that the Microsoft Edge WebDriver (msedgedriver.exe) no longer sets a default port of 9515 when it is run and instead assigns one randomly.  This is the one for Edge version 128.0.2739.79.  Anyway, this means that the wonderful wd_demo.au3 doesn't work for Microsoft Edge at the moment unless you edit line 1255 of wd_demo.au3 and change it to:

_WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & @ScriptDir & '\msedge.log"')

This will then cause msedgedriver.exe to use port 9515 which is what wd_demo.au3 is expecting.

I don't know if this change is something will persist in future releases but this change should continue to work regardless.  This had me stumped for a while so I hope it saves someone else some time.

Link to comment
Share on other sites

Did you check recently merged pull requests ?

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

Link to comment
Share on other sites

Hi @Danp2, hi @mLipok 👋 ,

by the recently several questions regarding the "port-behavior-change" / "port-topic", we see the people leaning for the new release (v1.4.0 (I guess)).
When do you plan to publish this one? Because I think the users download the latest release instead of using the current "master" branch state.

I am curious about your feedback, thanks 🤝 .

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

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

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

this decision is up to you @Danp2 

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

17 minutes ago, Danp2 said:

I think you wrote this description, and not sure how it slipped through without further discussion. 😏

I don't think so 🤔 , maybe @mLipok had questions about the verbiage of URL option. But let's discuss this in the GitHub Issue 🤝 .

19 minutes ago, Danp2 said:

Soon I imagine.

Wonderful, thanks Dan 👌 .

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

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

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

21 hours ago, chinadoug said:

FYI.  It appears that the Microsoft Edge WebDriver (msedgedriver.exe) no longer sets a default port of 9515 when it is run and instead assigns one randomly.  This is the one for Edge version 128.0.2739.79.  Anyway, this means that the wonderful wd_demo.au3 doesn't work for Microsoft Edge at the moment unless you edit line 1255 of wd_demo.au3 and change it to:

_WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & @ScriptDir & '\msedge.log"')

This will then cause msedgedriver.exe to use port 9515 which is what wd_demo.au3 is expecting.

 

This doesn't work in my programs: I still get error 10 when using msedgedriver. And the second line "...Port , 9515" I did have before. Isn't that the same as --port=9515?

_WD_Option('Driver', $sWebDriverFileEdge)
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & $sLogsPath & 'edge.log"')

 

Edited by HJL
Link to comment
Share on other sites

But neither wd_demo nor my programm works with it. Where is the error?

Func _SetupEdge()
    Local $sFuncName = "SetupEdge"
    _WD_Option('Driver', $sWebDriverFileEdge)
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & $sLogsPath & 'edge.log"')
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"w3c": true,"excludeSwitches": [ "enable-automation"], "args":["user-data-dir=C:\\Menu\\EDGE_WD_Profile"]}}}}'
EndFunc   ;==>SetupEdge

 

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/09/21

 Latest update just released. See below for change log.

Quote

## [1.4.0] 2024-09-21

### Changed

- WD_GetTable: Trim whitespace in cell contents
- WD_Window: Add support for Restore option (@Sven-Seyfert)
- _WD_UpdateDriver: Optionally specific target browser version (@mlipok)

### Fixed

- wd_demo: Pass port number in DriverParams
- _WD_JsonActionKey: Don't encode Unicode characters

### Project

- __WD_ErrHnd: Enhance to handle COM errors (@mlipok)

 

Link to comment
Share on other sites

Func _SetupEdge()
    Local $sFuncName = "SetupEdge"
    _WD_Option('Driver', $sWebDriverFileEdge)
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & $sLogsPath & 'edge.log"')
    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"w3c": true,"excludeSwitches": [ "enable-automation"], "args":["user-data-dir=C:\\BlpMenu\\EDGE_WD_Profile"]}}}}'
EndFunc   ;==>SetupEdge

===================================================================================

_WD_Option ==> Success [0] : Parameters:   Option=Driver   Value=i:\blpmenu\webdriver\user\msedgedriver.exe
_WD_Option ==> Success [0] : Parameters:   Option=Port   Value=9515
_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--log-path="c:\webdriver\msedge.log"
@@ Debug(2111) : 4e3.StartAnmeldung: 2019 Aufruf _WD_Startup
_WD_GetFreePort ==> Success [0 / 9515] : Parameters:   MinPort=9515   MaxPort=Default
_WD_IsLatestRelease ==> Success [0] : True
_WD_Startup: OS:    WIN_10 X64 19045 
_WD_Startup: AutoIt:    3.3.16.1
_WD_Startup: Webdriver UDF: 1.4.0 (Up to date)
_WD_Startup: WinHTTP:   1.6.4.2
_WD_Startup: Driver:    i:\blpmenu\webdriver\user\msedgedriver.exe (32 Bit)
_WD_Startup: Params:    --log-path="c:\webdriver\msedge.log"
_WD_Startup: Port:  9515
_WD_Startup: Command:   "i:\blpmenu\webdriver\user\msedgedriver.exe" --log-path="c:\webdriver\msedge.log" 
_WD_Startup ==> Success [0]
@@ Debug(2113) : 4e4.StartAnmeldung: 2021 nach BLP-WD_Startup und BrowserSetup @error=0
__WD_Post ==> Send / Recv error [6] : HTTP status = 0
_WD_CreateSession ==> Webdriver Exception [10]

===================================================================================

Starting Microsoft Edge WebDriver 129.0.2792.52 (6462e8fc16ec8b62bef06801adff3cbeccd6a7d4) on port 0
To submit feedback, report a bug, or suggest new features, please visit https://github.com/MicrosoftEdge/EdgeWebDriver

Only local connections are allowed.
Please see https://aka.ms/WebDriverSecurity for suggestions on keeping Microsoft Edge WebDriver safe.

Microsoft Edge WebDriver was started successfully.
msedgedriver was started successfully on port 56004.

Hi Dan, I hope this information helps to see my problem with MsEdge. I define port 9515 and it was startet with port 56004.

Link to comment
Share on other sites

Hi @HJL 👋 ,https://github.com/Sven-Seyfert/autoit-webdriver-boilerplate?tab=readme-ov-file#configuration

this output line does not include --port=9515, which should be the case.

_WD_Startup: Command:   "i:\blpmenu\webdriver\user\msedgedriver.exe" --log-path="c:\webdriver\msedge.log"
  • Your capabilities string looks good, so follow the suggestion of @Danp2.
  • You could also try to skip the user-data-dir and see if the behavior is still the same.

Still no luck? Please tryout this: https://github.com/Sven-Seyfert/autoit-webdriver-boilerplate

  • clone the repo (or download the latest release)
  • read the README.md file
  • set msedge (like described here)
  • run it and let us know if it works

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

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

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

Good point @SOLVE-SMART. It's like the code shown wasn't the actual code that was run to generate the logs because the line

_WD_Option('DriverParams', '--port=9515 --verbose --log-path="' & $sLogsPath & 'edge.log"')

doesn't match the output

_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--log-path="c:\webdriver\msedge.log"

 

Link to comment
Share on other sites

Another question: is it possible to hide the info about automation with a param for chromedriver or msedgedriver setup? It always takes a lot of place in the window.

image.png.a255c58da63944ce49fd0b8699bf0cdc.png

Edited by HJL
Link to comment
Share on other sites

The condition (option) is "--enable-automation" and I believe you already used it before in your capabilities string....
I do it in this way ...

_WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')

... and that's enough.

Anyways, when you struggle with the width and height of the *driver, you can also set the browser mode to maximize or even to fullscreen (which should do a F11).

_WD_Window($sSession, 'maximize')

; or 

_WD_Window($sSession, 'fullscreen')

I hope this will help you 👌 .
In case your native language is german (because of "benzinpreise.de"), you could also see some of my how-to videos here, to get a bit of a crash course for the webdriver.

Best regards
Sven

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

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

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Link to comment
Share on other sites

  • 2 weeks later...

Dear Danp2

i was using 

$sCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"}}}}'

i changed to:

Func SetupChrome();$bHeadless)
    $bHeadless = True
    _WD_Option('Driver', 'chromedriver.exe')
    Local $iPort = _WD_GetFreePort(5555, 5600)
    
    If @error Then Return SetError(@error, @extended, 0)

    _WD_Option('Port', $iPort)
    _WD_Option('DriverParams', '--port=' & $iPort & ' --verbose --log-path="' & @ScriptDir & '\chrome.log"')
     ;;$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"}}}}'

    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')

    If $bHeadless Then _WD_CapabilitiesAdd('args', '--headless')
    _WD_CapabilitiesDump(@ScriptLineNumber) ; dump current Capabilities setting to console - only for testing in this demo
    Local $sCapabilities = _WD_CapabilitiesGet()
    
    Return $sCapabilities
EndFunc   ;==>SetupChrome

Spoiler

_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_11 X64 22631 
_WD_Startup: AutoIt:    3.3.16.1
_WD_Startup: Webdriver UDF:    1.4.0 (Up to date)
_WD_Startup: WinHTTP:    1.6.4.1 (Download latest source at <https://raw.githubusercontent.com/dragana-r/autoit-winhttp/master/WinHttp.au3>)
_WD_Startup: Driver:    chromedriver.exe (64 Bit)
_WD_Startup: Params:    --port=5555 --verbose --log-path="C:\Users\HP\Desktop\AutoIt\chrome.log"
_WD_Startup: Port:    5555
_WD_Startup: Command:    "chromedriver.exe" --port=5555 --verbose --log-path="C:\Users\HP\Desktop\AutoIt\chrome.log" 
_WD_Startup ==> Success [0]
$sCapabilities : {
    "capabilities":{
        "alwaysMatch":{
            "goog:chromeOptions":{
                "w3c":true,
                "excludeSwitches":[
                    "enable-automation"
                ],
                "args":[
                    "--headless"
                ]
            }
        }
    }
}
__WD_Post ==> Success [0] : HTTP status = 200
_WD_CreateSession ==> Success [0] : c05a97c2784ba18b1cd92cbdff57f62c
$sSession : c05a97c2784ba18b1cd92cbdff57f62c
_WD_Action ==> Invalid data type [3] : (Actions|Back|Forward|Refresh|Title|Url) $sCommand=>default
__WD_Get ==> Success [0] : HTTP status = 200
_WD_Window ==> Success [0] : Parameters:   Command=HANDLES   Option=Default
__WD_Post ==> No match [8] : HTTP status = 404
_WD_FindElement ==> No match [8] : Parameters:   Strategy=xpath   Selector=/html/body/div[1]/div[5]/div/div/div/div[3]/div[3]/div/div[2]/div/div[3]/div/div[4]/div[2]/div/div/span/span/div/div[1]/div/div[2]/div/div/div[2]/span[2]/div   StartNodeID=Default   Multiple=Default   ShadowRoot=Default
__WD_Post ==> No match [8] : HTTP status = 404
_WD_ElementAction ==> No match [8] : Parameters:   Command=Clear   Option=Default
__WD_Get ==> Success [0] : HTTP status = 200

 

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