Jump to content

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


Danp2
 Share

Recommended Posts

On 30/1/2018 at 6:53 PM, Danp2 said:

@NguyenLe Please define "turn off the display". I interpret that to mean that you turned off the computer monitor. However, it could also mean hiding the browser window like I mentioned here --

Which of these is the correct interpretation? Also, post some code showing the issue so that we can try it on our end.

Hello @Danp2 ,

It seems to have returned to normal after I restarted my computer
Thank you very much

Link to comment
Share on other sites

Just released updated version on GH. I stuck with using the existing WinHTTP UDF for the following reasons --

  • The WinHTTP UDF is well defined and tested
  • It avoids all issues related to COM errors, alternative error handlers, etc
  • I'm not concerned about the differences in licensing
  • It was working fine in my testing

Look forward to your feedback / testing. :)

Link to comment
Share on other sites

Do you want me to do a PullRequest for COM Error Handling ?

Today I have some spare time.

 

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

Did you anywhere on GitHub put link to this AutoIt Forum Support Topic  ?
Did you put this link also into core UDF ?

 

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

@Danp2 If I connect to a new tab and reconnect to the previous tab I can not get the text of the alert

My Code: 

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, 'http://google.com')
_WD_ExecuteScript($sSession, 'window.open()','{}')
$Handle = _WD_Window($sSession, 'handle', '')
;Sleep(500)
_WD_NewTab($sSession, True)
Sleep(500)
_WD_Window($sSession, 'Switch' ,'{"handle":"' & $Handle & '"}')
Sleep(500)
_WD_ExecuteScript($sSession, "alert('testing 123')")
Sleep(1000)
$aHandles = _WD_Window($sSession, 'handles', '')
$sTabHandle = $aHandles[UBound($aHandles) - 1]
_WD_Window($sSession, 'Switch', '{"handle":"' & $sTabHandle & '"}')
Sleep(1000)
_WD_Window($sSession, 'Switch' ,'{"handle":"' & $Handle & '"}')
Sleep(1000)
$Text = _WD_Alert($sSession, 'gettext')
_WD_Alert($sSession, 'accept')
MsgBox(0,'Test Alert Text',$Text)

My Console:

_WD_Alert: {"value":{"error":"no alert open","message":"(Session infochrome=64.0.3282.140)","stacktrace":"Backtrace:\n\t(No symbol) [0x0117C2F0]\n\t(No symbol) [0x0116473D]\n\t(No symbol) [0x01133D93]\n\t(No symbol) [0x0113045D]\n\t(No symbol) [0x010F3CA3]\n\t(No symbol) [0x01115B6A]\n\t(No symbol) [0x010F38F7]\n\t(No symbol) [0x011159FB]\n\t(No symbol) [0x011006B4]\n\t(No symbol) [0x01101C86]\n\t(No symbol) [0x01101C09]\n\tGetHandleVerifier [0x01196C37+62007]\n\t(No symbol) [0x01180453]\n\t(No symbol) [0x0114CF76]\n\t(No symbol) [0x0114D365]\n\t(No symbol) [0x0114D47E]\n\t(No symbol) [0x01182527]\n\t(No symbol) [0x0114CCBF]\n\t(No symbol) [0x0114DFBF]\n\t(No symbol) [0x01149D6B]\n\t(No symbol) [0x01149EC3]\n\t(No symbol) [0x0115BEB9]\n\tBaseThreadInitThunk [0x7703336A+18]\n\tRtlInitializeExceptionChain [0x77569882+99]\n\tRtlInitializeExceptionChain [0x77569855+54]\n"}}

 

Untitled.png

Link to comment
Share on other sites

I see a few issues  --

  1. This line is invalid
    $Handle = _WD_Window($sSession, 'handle', '')

    Change 'handle' to 'window' to retrieve the handle for the currently active window. 

  2.  Using Chrome, the alert disappears when you switch tabs. This occurs even when you manually change tabs. You can test this yourself by hitting F12 to bring up the developer console and manually issuing the call to Alert. This doesn't occur with Firefox.

P.S. Next time post the full console output. ;-)

Link to comment
Share on other sites

@NguyenLe Yes, I see that from your post. But that's not how it behaves for me and not how it is designed to behave based upon the link I posted in #90 above.

What version of Chrome was you using? 32 or 64 bit? Anything else you can think of that would be affecting this (ie: Chrome setting or extension that would affect this)?

Link to comment
Share on other sites

@NguyenLe Sorry, but you can't just post an image and expect us to know what has occurred. 

Also, I went to this site in Chrome and encountered the same delay in the site loading. This appears to be by design; it is the DDos protection from Cloudflare. Since this occurs in a standard browser session, you can't expect the behavior to be different when using the Web Driver. 

There are likely ways to deal with this. One thought would be to write a function that loops for a defined period, retrieving the site's text and watching for the existence or non-existence of a provided text phrase. This could be a good "helper" function. Now someone just needs to write it. :)

Link to comment
Share on other sites

8 minutes ago, Danp2 said:

@NguyenLe Sorry, but you can't just post an image and expect us to know what has occurred. 

Also, I went to this site in Chrome and encountered the same delay in the site loading. This appears to be by design; it is the DDos protection from Cloudflare. Since this occurs in a standard browser session, you can't expect the behavior to be different when using the Web Driver. 

There are likely ways to deal with this. One thought would be to write a function that loops for a defined period, retrieving the site's text and watching for the existence or non-existence of a provided text phrase. This could be a good "helper" function. Now someone just needs to write it. :)

Ok, Thank you.

Link to comment
Share on other sites

I can not use the Click Element command in Firefox

My Code:

SetupGecko()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, 'http://google.com')
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='gsfi']")
_WD_ElementAction($sSession, $sElement, 'value','Hello')

My Console:

_WDStartup: OS: WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt: 3.3.14.2
_WDStartup: WD.au3: 0.1.0.6
_WDStartup: Driver: geckodriver.exe
_WDStartup: Params: --log trace
_WDStartup: Port:   4444
__WD_Post: URL=HTTP://127.0.0.1:4444/session; $sData={"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}
__WD_Post: StatusCode=200; ResponseText={"value": {"sessionId":"72ea7fca-2466-46cb-a334-5dbd8cdc7dba","capabilities":{"acceptInsecureCerts":true,"browserName":"firefox","browserVersion":"58.0.1","moz:accessibilityChecks":false,"moz:headless":false,"moz:processID":3708,"moz:profile":"C:\\Users\\PC\\AppData\\Local\\Temp\\rust_mozprofile.yhmYGIKQ7K6Z","moz:webdriverClick":true,"pageLoadStrategy":"normal","platformName":"windows_nt","platformVersion":"6.1","rotatable":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000}}}}
_WD_CreateSession: {"value": {"sessionId":"72ea7fca-2466-46cb-a334-5dbd8cdc7dba","capabilities":{"acceptInsecureCerts":true,"browserName":"firefox","browserVersion":"58.0.1","moz:accessibilityChecks":false,"moz:headless":false,"moz:processID":3708,"moz:profile":"C:\\Users\\PC\\AppData\\Local\\Temp\\rust_mozprofile.yhmYGIKQ7K6Z","moz:webdriverClick":true,"pageLoadStrategy":"normal","platformName":"windows_nt","platformVersion":"6.1","rotatable":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000}}}}
__WD_Post: URL=HTTP://127.0.0.1:4444/session/72ea7fca-2466-46cb-a334-5dbd8cdc7dba/url; $sData={"url":"http://google.com"}
__WD_Post: StatusCode=200; ResponseText={"value": {}}
_WD_Navigate: {"value": {}}
__WD_Post: URL=HTTP://127.0.0.1:4444/session/72ea7fca-2466-46cb-a334-5dbd8cdc7dba/element; $sData={"using":"xpath","value":"//a[@class='gsfi']"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"Unable to locate element: //a[@class='gsfi']","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x44eff6 - <no info>\n   4:           0x4322e1 - <no info>\n   5:           0x40ba4e - <no info>\n   6:           0x4119b9 - <no info>\n   7:           0x6d2c89 - <no info>\n   8:           0x426006 - <no info>\n   9:           0x6cd490 - <no info>\n  10:         0x77a75a4d - BaseThreadInitThunk"}}
_WD_FindElement: {"value":{"error":"no such element","message":"Unable to locate element: //a[@class='gsfi']","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x44eff6 - <no info>\n   4:           0x4322e1 - <no info>\n   5:           0x40ba4e - <no info>\n   6:           0x4119b9 - <no info>\n   7:           0x6d2c89 - <no info>\n   8:           0x426006 - <no info>\n   9:           0x6cd490 - <no info>\n  10:         0x77a75a4d - BaseThreadInitThunk"}}
_WD_FindElement ==> No match: no such element
__WD_Post: URL=HTTP://127.0.0.1:4444/session/72ea7fca-2466-46cb-a334-5dbd8cdc7dba/element//value; $sData={"id":"", "text":"Hello", "value":["H","e","l","l","o"]}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"unknown command","message":"POST /session/72ea7fca-2466-46cb-a334-5dbd8cdc7dba/element//value did not match a known command","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x43f00a - <no info>\n   4:           0x409e7b - <no info>\n   5:           0x41198a - <no info>\n   6:           0x6d2c89 - <no info>\n   7:           0x426245 - <no info>\n   8:           0x6cd490 - <no info>\n   9:         0x77a75a4d - BaseThreadInitThunk"}}
_WD_ElementAction: {"value":{"error":"unknown command","message":"POST /session/72ea7fca-2466-46cb-a334-5dbd8cdc7dba/element//value did not match a known command","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x43f00a - <no info>\n   4:           0x409e7b - <no info>\n   5:           0x41198a - <no info>\n   6:           0x6d2c89 - <no info>\n   7:           0x426245 - <no info>\n   8:           0x6cd490 - <no info>\n   9:         0x77a75a4d - BaseThreadInitThunk"}}

 

Link to comment
Share on other sites

11 minutes ago, NguyenLe said:

I can not use the Click Element command in Firefox

That's not the issue. 

11 minutes ago, NguyenLe said:

__WD_Post: URL=HTTP://127.0.0.1:4444/session/72ea7fca-2466-46cb-a334-5dbd8cdc7dba/element; $sData={"using":"xpath","value":"//a[@class='gsfi']"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"Unable to locate element: //a[@class='gsfi']","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x44eff6 - <no info>\n   4:           0x4322e1 - <no info>\n   5:           0x40ba4e - <no info>\n   6:           0x4119b9 - <no info>\n   7:           0x6d2c89 - <no info>\n   8:           0x426006 - <no info>\n   9:           0x6cd490 - <no info>\n  10:         0x77a75a4d - BaseThreadInitThunk"}} _WD_FindElement: {"value":{"error":"no such element","message":"Unable to locate element: //a[@class='gsfi']","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x44eff6 - <no info>\n   4:           0x4322e1 - <no info>\n   5:           0x40ba4e - <no info>\n   6:           0x4119b9 - <no info>\n   7:           0x6d2c89 - <no info>\n   8:           0x426006 - <no info>\n   9:           0x6cd490 - <no info>\n  10:         0x77a75a4d - BaseThreadInitThunk"}} _WD_FindElement ==> No match: no such element

You can't click an element that wasn't found by the prior function call. You'll need to locate the element first. Also some error checking in your code would help you here as well.

Link to comment
Share on other sites

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

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