Jump to content

WebDriver UDF (W3C compliant version) - 2022/10/03


Recommended Posts

v0.3.1.1 has been released with the following updates --

    - Fix (_WD_ElementOptionSelect): Correctly capture and re-throw errors (seadoggie01)
    - Fix (__WD_CloseDriver): Call ProcessWaitClose to ensure each process closes
    - Chore: Updated wd_demo.au3
        - Update DemoFrames example

Link to post
Share on other sites
  • Replies 1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Latest update just released. See below for change log.  

Introduction This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a f

All of the Webdriver UDF functions start with _WD_ (note the trailing underscore).

Posted Images

v0.4.0.1 has been released with the following updates --

    - Added: _WD_PrintToPDF
    - Fix (_WD_Window): Properly handle 'print' result
    - Changed (_WD_ElementActionEx): Added 'hide' and 'show' options
    - Changed (_WD_ElementAction): Added support for Shadow, CompRole & CompLabel actions
    - Changed (_WD_GetShadowRoot): Use _WD_ElementAction instead of _WD_ExecuteScript
    - Changed (_WD_NewTab): Use native Webdriver commands when Javascript isn't required
    - Changed (_WD_FindElement): Support shadow roots
    - Changed (_WD_Window): Support 'full' option for screenshots

Note: The shadow root stuff isn't officially in the specs yet, so YMMV when attempting to use it

Link to post
Share on other sites

@Danp2, Thank you for your hard work and timely updates of this wonderful UDF.
My Windows 10 cannot read the screenshot files generated by the current demo code. I commented out $sDecode = BinaryToString($bDecode) and changed FileWrite($hFileOpen, $sDecode) to FileWrite($hFileOpen, $bDecode) and it works perfect.

Link to post
Share on other sites

@CYCho I looked into the issue, but I wasn't able to replicate it. Can you share more details on your setup, such as --

  • Autoit version
  • Browser / webdriver version
  • Windows 10 version
  • Etc

Honestly, I'm not sure that the BinaryToString functionality is needed. Perhaps we can get feedback from some other folks that use the UDF.

Link to post
Share on other sites

My SciTE log:
 

_WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WDStartup: OS: WIN_10 WIN32_NT 19042 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.4.0.1 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --verbose --log-path="C:\Users\CYCho\OneDrive\Chrome\WebDriver\chrome.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"88.0....
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"88.0.4324.96","chrome":{"chromedriverVersion":"88.0.4324.27 (6347fe8bf1e48bd0c54d07dc55ca011cf40861c9-refs/branch-heads/4324@{#450})","userDataDir":"C:\\Users\\CYCho\\AppData\\Local\\Temp\\scoped_dir6212_1412050171"},"goog:chromeOptions":{"debuggerAddress":"localhost:50096"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:largeBlob":true,"webauthn:virtualAuthenticators":true},"sessionId":"f27c597f568f8a7963a761bd742e85ef"}}
Bypass: DemoTimeouts
Bypass: DemoNavigation
Bypass: DemoElements
Bypass: DemoScript
Bypass: DemoCookies
Bypass: DemoAlerts
Bypass: DemoFrames
Bypass: DemoActions
Bypass: DemoDownload
+Running: DemoWindows
__WD_Get: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"CDwindow-301AACFB0CEF79704C88655051A006E0"}...
_WD_Window: {"value":"CDwindow-301AACFB0CEF79704C88655051A006E0"}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/url; $sData={"url":"http://google.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Navigate: {"value":null}
__WD_Get: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"CDwindow-301AACFB0CEF79704C88655051A006E0"}...
_WD_Window: {"value":"CDwindow-301AACFB0CEF79704C88655051A006E0"}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window/new; $sData={"type":"tab"}
__WD_Post: StatusCode=200; ResponseText={"value":{"handle":"CDwindow-8BBB3F887DE3F4951EA71D5ACA06932C","type":"tab"}}...
_WD_Window: {"value":{"handle":"CDwindow-8BBB3F887DE3F4951EA71D5ACA06932C","type":"tab"}}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window; $sData={"handle":"CDwindow-8BBB3F887DE3F4951EA71D5ACA06932C"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Window: {"value":null}...
__WD_Get: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"CDwindow-8BBB3F887DE3F4951EA71D5ACA06932C"}...
_WD_Window: {"value":"CDwindow-8BBB3F887DE3F4951EA71D5ACA06932C"}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/url; $sData={"url":"http://yahoo.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Navigate: {"value":null}
__WD_Get: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window/rect
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":{"height":1030,"width":945,"x":10,"y":10}}...
_WD_Window: {"value":{"height":1030,"width":945,"x":10,"y":10}}...
Window Coords = 10 / 10 / 945 / 1030
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window; $sData={"handle":"CDwindow-301AACFB0CEF79704C88655051A006E0"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Window: {"value":null}...
__WD_Get: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/screenshot
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"iVBORw0KGgoAAAANSUhEUgAAA6EAAAOuCAYAAAD2DRH/AAAAAXNSR0IArs4c6QAAIABJREFUeJzs3Xl8FPX9x/H3zJ...
_WD_Window: {"value":"iVBORw0KGgoAAAANSUhEUgAAA6EAAAOuCAYAAAD2DRH/AAAAAXNSR0IArs4c6QAAIABJREFUeJzs3Xl8FPX9x/H3zJ...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/window; $sData={"handle":"CDwindow-8BBB3F887DE3F4951EA71D5ACA06932C"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Window: {"value":null}...
__WD_Get: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef/screenshot
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"iVBORw0KGgoAAAANSUhEUgAAA6EAAAOuCAYAAAD2DRH/AAAAAXNSR0IArs4c6QAAIABJREFUeJzs3Xd8W9X9P/6Xhi...
_WD_Window: {"value":"iVBORw0KGgoAAAANSUhEUgAAA6EAAAOuCAYAAAD2DRH/AAAAAXNSR0IArs4c6QAAIABJREFUeJzs3Xd8W9X9P/6Xhi...
+Finished: DemoWindows
Bypass: DemoUpload
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/f27c597f568f8a7963a761bd742e85ef
__WD_Delete: StatusCode=200; ResponseText={"value":null}...
_WD_DeleteSession: {"value":null}
+>08:21:16 AutoIt3.exe ended.rc:0
+>08:21:16 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 34.44

When I try to open the .png file, an alert pops up saying that the fiile cannot be opened because it is not a correct bitmap file or it may be in a format not supported by this device.

Link to post
Share on other sites

Strange. I'm running the exact same version of Window, Chrome, & Chromedriver. I was previously testing w/ Chrome 87, but updated just now and the results are the same for me. I do recall seeing a similar issue recently, but I don't remember if it was related to window screen captures or element screen captures.

If you view the PNG file in a text editor, do  you see anything unusual? Can you post the bad file as an attachment to this thread?

Link to post
Share on other sites
1 hour ago, Danp2 said:

I don't remember if it was related to window screen captures or element screen captures

I tested both window and element screen captures and the result was the same. Attached is a file from window screen capture. I tried all available apps to open the file but to no avail.

Edit: When I try to attach the file here, the following message pops up resulting in failure.

Edit2 : I changed the file extension to txt and uploaded it.
 

 

2021_01_20_09_31_52_WebDriver_UDF_W3C_compliant_version_01_16_2021_Page_46_AutoIt_Example_Sc.png

Screen2.txt

Edited by CYCho
Link to post
Share on other sites
  • 5 weeks later...

Hi guys

I have a little problem with the "clear" - action. I'm trying to delete the content of the input field and then insert $Name. "clear" deletes the text in the input box, but as soon as I add $Name, the deleted content appears again, with the new content inserted after it. Is this behavior intentional or do I not understand the function correctly? 

My assumption is that clear only works if the text to be deleted also appears in the html.

I have the latest version of udf & chromedriver.

Thank you for your help.

<input data-v-ded29398="" data-v-7db6081e="" name="designName" type="text" id="input-design-name" maxlength="50" class="design-name-input">
$Search = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='input-design-name']")
_WD_ElementAction($sSession, $Search, 'clear')
_WD_ElementAction($sSession, $Search, 'value', $Name)

 

Link to post
Share on other sites

@Danp2 Thanks. https://builtwith.com/spreadshirt.com does not detect the underlying framework. I doubt that I have enough knowledge to make framework specific code changes.

I think I will be more sucessfull with trying to make my old work-around work again. I used:

_WD_ElementAction($sSession, $Search, 'value', "\uE003")

but since I updated my webdriver udf (from 2019 version) , this does no longer send a backspace. It just inserts "\uE003" as text. 

Link to post
Share on other sites
  • 2 weeks later...

Hello @Danp2
Could you please help me with DesiredCapatibilities for Edge chromium ? I have entered this 
 

'{"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": true, ' & _
'"args": ["start-maximized", "load-extension=path_to_extension"]}}}}'

What only works is that it opens Webdriver for Edge, then it opens second command line for msedge then Edge browser appears with Extension but no automation happens

Also i had to remove 

{"binary": "' & StringReplace (@ProgramFilesDir, "\", "/") & '/Microsoft/Edge/Application/msedge.exe"

otherwise Edge browser would not appear. Could you please help me ?

Link to post
Share on other sites

Hi @rkskaras Can you provide more details please, such as --

  • Does it work if you remove the "load-extension" portion?
  • What extension are you trying to load?
  • Show us the results from the Scite output panel
23 minutes ago, rkskaras said:

Also i had to remove 

{"binary": "' & StringReplace (@ProgramFilesDir, "\", "/") & '/Microsoft/Edge/Application/msedge.exe"

otherwise Edge browser would not appear.

That's interesting because IIRC Edge wouldn't load without this when I first tested. Can you check and see where Edge is installed on your system? For me it now work both with and without the above.

Dan

Link to post
Share on other sites

Hello @Danp2,

20 hours ago, Danp2 said:

 

  • Does it work if you remove the "load-extension" portion?
  • What extension are you trying to load?
  • Show us the results from the Scite output panel

1. No, still no automation happens.
2. https://chrome.google.com/webstore/detail/enterprise-sso/mheiphfcfdhlkecdhpgblhpemkecaheh
3. 

_WDStartup: OS: WIN_10 WIN32_NT 18363 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.1.0.17
_WDStartup: Driver: dat/msedgedriver.exe
_WDStartup: Params: --verbose --log-path=""
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"ms:edgeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": true, "args": ["start-maximized"]}}}}
__WD_Post: StatusCode=500; ResponseText={"value":{"error":"unknown error","message":"unknown error: MSEdge failed to start: exited normally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from msedge location C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe is no longer running, so MSEdgeDriver is assuming that MSEdge has crashed.)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00007FF7191CAF92+241554]\n\tGetHandleVerifier [0x00007FF71993C9C8+2174200]\n\tGetHandleVerifier [0x00007FF7199611D6+2323718]\n\tGetHandleVerifier [0x00007FF719959B09+2293305]\n\tGetHandleVerifier [0x00007FF71998B6A0+2496976]\n\tGetHandleVerifier [0x00007FF71998799F+2481359]\n\tGetHandleVerifier [0x00007FF71996544A+2340730]\n\tGetHandleVerifier [0x00007FF71996608B+2343867]\n\tOrdinal0 [0x00007FF7191A2D01+77057]\n\tGetHandleVerifier [0x00007FF7199CA291+2753985]\n\tGetHandleVerifier [0x00007FF7197AF7FF+547631]\n\tGetHandleVerifier [0x00007FF7199CAB38+2756200]\n\tOrdinal0 [0x00007FF71939DC8E+2153614]\n\tOrdinal0 [0x00007FF71939CA84+2148996]\n\tOrdinal0 [0x00007FF71926D51E+906526]\n\tBaseThreadInitThunk [0x00007FFD0EA67C24+20]\n\tRtlUserThreadStart [0x00007FFD0EF6D721+33]\n"}}
_WD_CreateSession: {"value":{"error":"unknown error","message":"unknown error: MSEdge failed to start: exited normally.\n  (unknown error: DevToolsActivePort file doesn't exist)\n  (The process started from msedge location C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe is no longer running, so MSEdgeDriver is assuming that MSEdge has crashed.)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00007FF7191CAF92+241554]\n\tGetHandleVerifier [0x00007FF71993C9C8+2174200]\n\tGetHandleVerifier [0x00007FF7199611D6+2323718]\n\tGetHandleVerifier [0x00007FF719959B09+2293305]\n\tGetHandleVerifier [0x00007FF71998B6A0+2496976]\n\tGetHandleVerifier [0x00007FF71998799F+2481359]\n\tGetHandleVerifier [0x00007FF71996544A+2340730]\n\tGetHandleVerifier [0x00007FF71996608B+2343867]\n\tOrdinal0 [0x00007FF7191A2D01+77057]\n\tGetHandleVerifier [0x00007FF7199CA291+2753985]\n\tGetHandleVerifier [0x00007FF7197AF7FF+547631]\n\tGetHandleVerifier [0x00007FF7199CAB38+2756200]\n\tOrdinal0 [0x00007FF71939DC8E+2153614]\n\tOrdinal0 [0x00007FF71939CA84+2148996]\n\tOrdinal0 [0x00007FF71926D51E+906526]\n\tBaseThreadInitThunk [0x00007FFD0EA67C24+20]\n\tRtlUserThreadStart [0x00007FFD0EF6D721+33]\n"}}
_WD_CreateSession ==> Webdriver Exception: unknown error: MSEdge failed to start: exited normally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so MSEdgeDriver is assuming that MSEdge has crashed.)
__WD_Post: URL=HTTP://127.0.0.1:9515/session//url; $sData={"url":"https://website.com/"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"invalid session id","message":"invalid session id","stacktrace":"Backtrace:\n\tOrdinal0 [0x00007FF7191CAF92+241554]\n\tGetHandleVerifier [0x00007FF71993C832+2173794]\n\tGetHandleVerifier [0x00007FF719964D43+2338931]\n\tGetHandleVerifier [0x00007FF719987A7B+2481579]\n\tGetHandleVerifier [0x00007FF719985A00+2473264]\n\tGetHandleVerifier [0x00007FF71991D452+2045826]\n\tOrdinal0 [0x00007FF7191A2D01+77057]\n\tGetHandleVerifier [0x00007FF7199CA291+2753985]\n\tGetHandleVerifier [0x00007FF7197AF7FF+547631]\n\tGetHandleVerifier [0x00007FF7199CAB38+2756200]\n\tOrdinal0 [0x00007FF71939DC8E+2153614]\n\tGetHandleVerifier [0x00007FF71991C510+2041920]\n\tGetHandleVerifier [0x00007FF7199ED688+2898360]\n\tBaseThreadInitThunk [0x00007FFD0EA67C24+20]\n\tRtlUserThreadStart [0x00007FFD0EF6D721+33]\n"}}
_WD_Navigate: {"value":{"error":"invalid session id","message":"invalid session id","stacktrace":"Backtrace:\n\tOrdinal0 [0x00007FF7191CAF92+241554]\n\tGetHandleVerifier [0x00007FF71993C832+2173794]\n\tGetHandleVerifier [0x00007FF719964D43+2338931]\n\tGetHan

MS Edge is installed under C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe

Edited by rkskaras
Link to post
Share on other sites
1 hour ago, rkskaras said:

_WD_CreateSession ==> Webdriver Exception: unknown error: MSEdge failed to start: exited normally.   (unknown error: DevToolsActivePort file doesn't exist)   (The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so MSEdgeDriver is assuming that MSEdge has crashed.)

You will need to resolve this issue.

Link to post
Share on other sites

I'm writing a few apps needing to modify html after it finishes loading assorted websites with chromedriver.

One such application will implement an ADA feature to zoom the page for the visually impaired.
I tried :

 

_WD_Navigate($sSession, 'https://www.autoitscript.com/site/')
_WD_LoadWait($sSession, 200,5000)

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//head")
$sValue = _WD_ElementAction($sSession, $sElement, 'property', 'innerHTML')
$sValue=StringRegExpReplace($sValue, '([\n]*)', '') ;Remove LF's
$sZoomHead="<style>body {zoom: 4; -moz-transform: scale(3); -moz-transform-origin: 0 0;} </style>"
_WD_ExecuteScript($sSession,'document.head.innerHTML="' & $sZoomHead & $sValue & '"')


$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//body")
$sValue = _WD_ElementAction($sSession, $sElement, 'property', 'innerHTML')
$sValue=StringRegExpReplace($sValue, '([\n]*)', '') ;Remove LF's
$sZoomBody1="<div class='zoomed'>"
$sZoomBody2="</div>"
_WD_ExecuteScript($sSession,'document.head.innerHTML="' & $sZoomBody1 & $sValue & $sZoomBody2 & '"')

 

But it seems that because the <Head> and the <Body> has single or double quotes in it, it doesn't send the strings properly.

Does anyone know of any other ways or tips for doing this?

Thanks

Edited by NassauSky
Link to post
Share on other sites
  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2022/10/03
  • 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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...