Jump to content

WebDriver UDF - Help & Support (III)


Danp2
 Share

Recommended Posts

I know that there is _WD_LoadWait() function.
But I'm wondering how to use waiting and progress and offline and stalled and suspend events to check the current state.

Also how to use keydown and touchstart and touchmove events to check if user is manually interacting with browser.

Maybe somehow using JS + storages ?


Some references:

https://www.w3schools.com/jsref/dom_obj_event.asp

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

Also how to check current state using:

https://www.w3schools.com/jsref/obj_progressevent.asp

?

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

5 hours ago, Danp2 said:

@mLipokGenerally, you shouldn't need to worry about that because the webdriver handles this automatically for you. However, you should be able to do it with _WD_ExecuteScript and Javascript.

As I used such function in IE thus migrating to WD I try to have according replacement at first step, after some time I will refactor code to remove such functions, but temporarily at the migration stage, I prefer to repeat all the steps that were performed in IE.

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

On 7/25/2022 at 11:04 PM, mLipok said:

or:

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "label[for='input34']")
_WD_ElementAction($sSession, $sElement, 'CLICK')

 

This did not work for me. The _WD_FindElement result was an error.
Using the line below, the result I get equals $_WD_ERROR_Success.

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@name='remember']")

However, the _WD_ELEmentAction "click" does not work on the checkbox.
One other problem I encountered was also that input34 sometime (don't know why) changes to inputXX with XX being a seemingly random numbers.
Your post however help me to rethink the problem and fix it with also the help op Danp2.

Edited by Jemboy
Link to comment
Share on other sites

in one of my IE project I had such scenario

Local $oIE_Main = ....
Local $oFrame_1 = ....
Local $oFrame_2 = ....
_IENavigate($oFrame_2, $sURL)

I mean I need to navigate document in $oFrame_2 without moving $oFrame_1 and without moving $oIE_Main.

As so far I tries this scenario:

_WD_FrameEnter($sSession, 2)
_WD_Navigate($sSession, $sURL)

I was in hope that only  second frame will navigate to $sURL but unfortunately navigation was taken for entire browser, not for specific frame.

How to solve this issue ?

As so far I found:

https://stackoverflow.com/questions/15464808/how-to-navigate-a-subframe-inside-a-frameset-using-selenium-webdriver

But it is about navigating between frame aka switching.
I can switch to frame with WebDriver in AutoIt.

When I already swithc to desired frame how to navigate this frame to different URL ?
 

 

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

For an hour I searched first for the cause of the problem in my IE to WD migration project.
Then I wrote a question (post above).
And a while ago, I found a solution.

https://stackoverflow.com/questions/22095346/loading-a-url-in-a-frame-using-selenium-c-sharp

_WD_FrameEnter($sSession, Null)
    _WD_FrameEnter($sSession, 2)
    Local $s_JavaScript = "window.location.href='" & $s_Warehouse_url & "'"
    _WD_ExecuteScript($sSession,$s_JavaScript)

 

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

On 7/26/2022 at 11:15 AM, Danp2 said:

@Jemboy

  1. Your post has been moved to this thread in the GH&S section (thanks to the @mod that moved it for me). General questions regarding the UDF belong here, not in the thread in the AutoIt Example Scripts section.
     
  2. Your attempt to check the checkbox using _WD_ElementAction / Select command will never work.
     
  3. Try using WD_ElementActionEx / Check command instead.
     
  4. I doubt that you will achieve the goal of a faster login unless you switch to using an existing user profile.

@Danp21. Thanks voor the move, must haven "sleeping"😁

2. / 3. Thanks for this tip. After updating the webdriver UDF, I found the "check" command at the  WD_ElementActionEx function, which worked!!!👏👏

4. Your are right again! I chan check the checkbox now, but it is not remembered for future sessions.🙁

Link to comment
Share on other sites

@jiataifengCalling _WD_Shutdown() will close the webdriver without closing the browser window.

Note: You will probably experience other "console" windows appearing after you do this. This is a known issue with chromedriver (and probably msedgedriver) when forcibly closed.

Another option would be to hide the chromedriver window instead of forcibly closing it.

Edited by Danp2
Link to comment
Share on other sites

Greetings everyone, would like to kindly request a little from the more knowledgeable in this field. 

End goal:
I am trying to automate some of the print settings off the Chrome - Print Dialog box for user to minimize mistakes in selecting wrong printer destination, paper size, scaling factor, etc.

At the first stage now, which is to reach the elements on chrome://print (page source when the Print Dialog box pops up).
I've achieved it through iterating through the shadow-roots and finding the element.
Print Destination <-- I've managed to to select the options in the dropdown list into an ArrayDisplay and displayed the array.

image.png.68937dbd77a8a3a3ddf7d55b14e299a8.png

image.png.8fda6ed360e084c983b98ec0122c41c1.png

However, I'm stuck at attempting to select a different option in the dropdown using _WD_ElementOptionSelect.
It fails and just remains at the current value.

Attached herewith are snippets of the code and debug log.
 

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include "wd_helper.au3"
#include "wd_capabilities.au3"

_Example()

Func _Example()

    Local $WD_SESSION = SetupChrome()
    Local $sFilePath = "chrome://print"
    _WD_Navigate($WD_SESSION, $sFilePath)

    ;Iterate through shadow-root (SR) to get to desired element
    $printPreviewApp_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByXPath, "//print-preview-app")
    $printPreviewSidebar_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "print-preview-sidebar#sidebar", $printPreviewApp_SR)
    $containerDiv = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "#container", $printPreviewSidebar_SR, Default, True)
    $printPreviewDestinationSettings_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "#destinationSettings", $containerDiv)
    $printPreviewDestinationSelect_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "#destinationSelect", $printPreviewDestinationSettings_SR)

    $sSelectElement = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "select", $printPreviewDestinationSelect_SR, '', True)
    $aOptionsList = _WD_ElementSelectAction($WD_SESSION, $sSelectElement, "options")
    $sCurrentValue = _WD_ElementSelectAction($WD_SESSION, $sSelectElement, "value")

    ;_ArrayDisplay ( Const ByRef $aArray [, $sTitle = "ArrayDisplay" [, $sArrayRange = "" [, $iFlags = 0 [, $vUser_Separator = Default [, $sHeader = Default [, $iMax_ColWidth = Default]]]]]] )
    ; -Parameters-
    ; $aArray - Array to display
    ; $sTitle - Title for dialog box
    ; $iFlags - Determine UDF options - 0 (default) - Column text alignment - Left
    ; $vUser_Separator - Default
    ; $sHeader - 'Value | Label'
    _ArrayDisplay($aOptionsList, '$aOptionsList, CurrentValue = ' & $sCurrentValue, '', 0, Default, '                          Value                          |                          Label                          ')


    ;$sValue = "Save as PDF/local/"
    _WD_ElementOptionSelect($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "select option[value=""Save as PDF/local/""]")
    $sCurrentValue = _WD_ElementSelectAction($WD_SESSION, $sSelectElement, "value")
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, 'Using CSSSelector #' & @ScriptLineNumber, 'After selecting Value "' & "Save as PDF" & '"' & @CRLF & 'CurrentValue = ' & $sCurrentValue)
    _WD_Shutdown()
EndFunc

Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

    _WD_Startup()

;~  Local $sCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"]}}}}'
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    Local $sCapabilities = _WD_CapabilitiesGet()

    Local $WD_SESSION = _WD_CreateSession($sCapabilities)
    _WD_ConsoleVisible(False)

    Return $WD_SESSION
EndFunc

Log:

_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=--verbose --log-path="C:\Program Files (x86)\AutoIt3\Extras\au3WebDriver-0.10.0\chrome.log"
_WD_IsLatestRelease ==> Success [0] : True
_WD_Startup: OS:    WIN_10 WIN32_NT 17763 
_WD_Startup: AutoIt:    3.3.16.0
_WD_Startup: Webdriver UDF: 0.10.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 (32 Bit)
_WD_Startup: Params:    --verbose --log-path="C:\Program Files (x86)\AutoIt3\Extras\au3WebDriver-0.10.0\chrome.log"
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe" --verbose --log-path="C:\Program Files (x86)\AutoIt3\Extras\au3WebDriver-0.10.0\chrome.log" 
_WD_Startup ==> Success [0]
_WD_CapabilitiesAdd ==> Success [0] : Successfully used [alwaysMatch]  with specified browser: chrome
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
_WD_CapabilitiesAdd ==> Success [0] : Successfully added capability
__WD_Post ==> Success [0] : HTTP status = 200
_WD_CreateSession ==> Success [0] : 2d61b526604f726605456e76d746838b
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Navigate ==> Success [0] : Parameters:   URL=chrome://print
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=xpath   Selector=//print-preview-app   StartNodeID=   Multiple=Default   ShadowRoot=Default
__WD_Get ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=shadow   Option=Default
_WD_GetShadowRoot ==> Success [0] : Parameters:    Strategy=xpath    Selector=//print-preview-app    StartElement=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=css selector   Selector=print-preview-sidebar#sidebar   StartNodeID=f6ed3801-3b8c-435d-97f7-16e8aba755a3   Multiple=Default   ShadowRoot=Default
__WD_Get ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=shadow   Option=Default
_WD_GetShadowRoot ==> Success [0] : Parameters:    Strategy=css selector    Selector=print-preview-sidebar#sidebar    StartElement=f6ed3801-3b8c-435d-97f7-16e8aba755a3
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=css selector   Selector=#container   StartNodeID=49abd27c-8a83-4c62-86c4-e1788fe70f6d   Multiple=Default   ShadowRoot=True
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=css selector   Selector=#destinationSettings   StartNodeID=8aff4d0c-ba1f-4c85-a98c-920e317be24d   Multiple=Default   ShadowRoot=Default
__WD_Get ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=shadow   Option=Default
_WD_GetShadowRoot ==> Success [0] : Parameters:    Strategy=css selector    Selector=#destinationSettings    StartElement=8aff4d0c-ba1f-4c85-a98c-920e317be24d
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=css selector   Selector=#destinationSelect   StartNodeID=70f4a5eb-8b26-4915-a7fb-c6e6d7b9ff83   Multiple=Default   ShadowRoot=Default
__WD_Get ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=shadow   Option=Default
_WD_GetShadowRoot ==> Success [0] : Parameters:    Strategy=css selector    Selector=#destinationSelect    StartElement=70f4a5eb-8b26-4915-a7fb-c6e6d7b9ff83
__WD_Post ==> Success [0] : HTTP status = 200
_WD_FindElement ==> Success [0] : Parameters:   Strategy=css selector   Selector=select   StartNodeID=ed9a64cd-c93e-47f0-919a-65e59b8da569   Multiple=   ShadowRoot=True
__WD_Get ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=property   Option=nodeName
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ExecuteScript ==> Success [0]
_WD_ElementSelectAction ==> Success [0 / 0] : $sCommand = options : Result = (array)
__WD_Get ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=property   Option=nodeName
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ExecuteScript ==> Success [0]
_WD_ElementSelectAction ==> Success [0 / 0] : $sCommand = value : Result = HP Color LaserJet MFP M477fdn (7B2122)/local/
__WD_Post ==> No match [8] : HTTP status = 404
_WD_FindElement ==> No match [8] : Parameters:   Strategy=css selector   Selector=select option[value="Save as PDF/local/"]   StartNodeID=   Multiple=Default   ShadowRoot=Default
_WD_ElementOptionSelect ==> No match [8] : Parameters:    Strategy=css selector    Selector=select option[value="Save as PDF/local/"]    StartElement=Default
__WD_Get ==> Success [0] : HTTP status = 200
_WD_ElementAction ==> Success [0] : Parameters:   Command=property   Option=nodeName
__WD_Post ==> Success [0] : HTTP status = 200
_WD_ExecuteScript ==> Success [0]
_WD_ElementSelectAction ==> Success [0 / 0] : $sCommand = value : Result = HP Color LaserJet MFP M477fdn (7B2122)/local/
+>16:14:54 AutoIt3.exe ended.rc:0
+>16:14:55 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 29.68

As seen here, it returns HTTP status = 404 when I attempt to select the option "Save as PDF/local/" by its value and the selected element remains my HP printer.


image.png.46418ff8bf21f25148173ea3b61d8e10.png
 

Appreciate if someone could shed some light?

Thank you!
 

image.png

Link to comment
Share on other sites

@ZulYou target element is located within a shadow root, which isn't currently supported by _WD_ElementOptionSelect. However, you can still handle this by manually performing the actions of _WD_ElementOptionSelect --

  • Use _WD_FindElement to locate the desired element
  • Use _WD_ElementAction to click it

HTH,

Dan

Link to comment
Share on other sites

4 minutes ago, Danp2 said:
  • Use _WD_FindElement to locate the desired element
  • Use _WD_ElementAction to click it

Initially I think I could suggest a better solution, but now I'm busy at work.
I will try to check in the next few hours.

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

7 minutes ago, Danp2 said:

I suspect that you are going to suggest a solution that doesn't use "chrome://print".

No

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

1 hour ago, Zul said:

I am trying to automate some of the print settings off the Chrome - Print Dialog box for user to minimize mistakes in selecting wrong printer destination, paper size, scaling factor, etc...... 

image.png.68937dbd77a8a3a3ddf7d55b14e299a8.png

image.png.8fda6ed360e084c983b98ec0122c41c1.png

 

 

it is interesting to me... so at first step I refactor your code a little

  • _WD_UpdateDriver
  • error checking
  • variable doclaration with Local to fit Au3Check requirments

 

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include "wd_capabilities.au3"
#include "wd_helper.au3"

_Example()

Func _Example()

    _WD_UpdateDriver('chrome')
    Local $WD_SESSION = SetupChrome()
    If @error Then Return SetError(@error, @extended, 0)

    Local $sFilePath = "chrome://print"
    _WD_Navigate($WD_SESSION, $sFilePath)

    ;Iterate through shadow-root (SR) to get to desired element
    Local $printPreviewApp_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByXPath, "//print-preview-app")
    Local $printPreviewSidebar_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "print-preview-sidebar#sidebar", $printPreviewApp_SR)
    Local $containerDiv = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "#container", $printPreviewSidebar_SR, Default, True)
    Local $printPreviewDestinationSettings_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "#destinationSettings", $containerDiv)
    Local $printPreviewDestinationSelect_SR = _WD_GetShadowRoot($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "#destinationSelect", $printPreviewDestinationSettings_SR)

    Local $sSelectElement = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "select", $printPreviewDestinationSelect_SR, '', True)
    Local $aOptionsList = _WD_ElementSelectAction($WD_SESSION, $sSelectElement, "options")
    Local $sCurrentValue = _WD_ElementSelectAction($WD_SESSION, $sSelectElement, "value")

    ;_ArrayDisplay ( Const ByRef $aArray [, $sTitle = "ArrayDisplay" [, $sArrayRange = "" [, $iFlags = 0 [, $vUser_Separator = Default [, $sHeader = Default [, $iMax_ColWidth = Default]]]]]] )
    ; -Parameters-
    ; $aArray - Array to display
    ; $sTitle - Title for dialog box
    ; $iFlags - Determine UDF options - 0 (default) - Column text alignment - Left
    ; $vUser_Separator - Default
    ; $sHeader - 'Value | Label'
    _ArrayDisplay($aOptionsList, '$aOptionsList, CurrentValue = ' & $sCurrentValue, '', 0, Default, '                          Value                          |                          Label                          ')

    ;$sValue = "Save as PDF/local/"
    _WD_ElementOptionSelect($WD_SESSION, $_WD_LOCATOR_ByCSSSelector, "select option[value=""Save as PDF/local/""]")
    $sCurrentValue = _WD_ElementSelectAction($WD_SESSION, $sSelectElement, "value")
    MsgBox($MB_OK + $MB_TOPMOST + $MB_ICONINFORMATION, 'Using CSSSelector #' & @ScriptLineNumber, 'After selecting Value "' & "Save as PDF" & '"' & @CRLF & 'CurrentValue = ' & $sCurrentValue)
    _WD_Shutdown()
EndFunc

Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

    _WD_Startup()

;~  Local $sCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"]}}}}'
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    Local $sCapabilities = _WD_CapabilitiesGet()

    Local $WD_SESSION = _WD_CreateSession($sCapabilities)
    If @error Then Return SetError(@error, @extended, '')
    _WD_ConsoleVisible(False)
    Return $WD_SESSION
EndFunc

 

 

Edited by mLipok
removed my local #include from code

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

1 hour ago, Danp2 said:

I suspect that you are going to suggest a solution that doesn't use "chrome://print".

I said no because easier way to do this is:

Local $a_Printer[] = ['Save as PDF']
_WD_ElementSelectAction($WD_SESSION, $sSelectElement, "MULTISELECT", $a_Printer)


I just had to check the code given by @Zul.
Finally I changed the code, a little more by adding separate function: _WD_ChromePrintingGUI()

 

Here is better example:
 

#include <Array.au3>
#include <MsgBoxConstants.au3>
#include "wd_capabilities.au3"
#include "wd_helper.au3"

_Example()

Func _Example()

    _WD_UpdateDriver('chrome')
    Local $sSession = SetupChrome()
    If @error Then Return SetError(@error, @extended, 0)

    _WD_Navigate($sSession, 'https://www.google.com/')
    _WD_LoadWait($sSession, 1000)

    Local $sFilePath = "chrome://print"
    _WD_Navigate($sSession, $sFilePath)

    _WD_ChromePrintingGUI($sSession, 'PDFCreator')
;~  _WD_ChromePrintingGUI($sSession, 'Save as PDF')
;~  _WD_ChromePrintingGUI($sSession, 'Zapisz jako PDF')

    _WD_Shutdown()
EndFunc   ;==>_Example

; #FUNCTION# ====================================================================================================================
; Name ..........: _WD_ChromePrintingGUI
; Description ...: Print on specified printer using Chrome printing GUI
; Syntax ........: _WD_ChromePrintingGUI($sSession[, $sPrinterName = Default])
; Parameters ....: $sSession            - Session ID from _WD_CreateSession
;                  $sPrinterName        - printer name to be used with Chrome printing GUI. Default returns list of printers
; Return values .: None
; Author ........: Zul
; Modified ......: mLipok
; Remarks .......:
; Related .......:
; Link ..........: https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/?do=findComment&comment=1505239
; Example .......: No
; ===============================================================================================================================
Func _WD_ChromePrintingGUI($sSession, $sPrinterName = Default)
    ; Iterate through shadow-root (SR) to get to desired element
    Local $printPreviewApp_SR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByXPath, "//print-preview-app")
    Local $printPreviewSidebar_SR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "print-preview-sidebar#sidebar", $printPreviewApp_SR)
    Local $containerDiv = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "#container", $printPreviewSidebar_SR, Default, True)
    Local $printPreviewDestinationSettings_SR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "#destinationSettings", $containerDiv)
    Local $printPreviewDestinationSelect_SR = _WD_GetShadowRoot($sSession, $_WD_LOCATOR_ByCSSSelector, "#destinationSelect", $printPreviewDestinationSettings_SR)

    Local $sSelectElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "select", $printPreviewDestinationSelect_SR, '', True)
    Local $aOptionsList = _WD_ElementSelectAction($sSession, $sSelectElement, "options")
    Local $sCurrentValue = _WD_ElementSelectAction($sSession, $sSelectElement, "value")

    ;_ArrayDisplay ( Const ByRef $aArray [, $sTitle = "ArrayDisplay" [, $sArrayRange = "" [, $iFlags = 0 [, $vUser_Separator = Default [, $sHeader = Default [, $iMax_ColWidth = Default]]]]]] )
    ; -Parameters-
    ; $aArray - Array to display
    ; $sTitle - Title for dialog box
    ; $iFlags - Determine UDF options - 0 (default) - Column text alignment - Left
    ; $vUser_Separator - Default
    ; $sHeader - 'Value | Label'
    Local Const $s_Header = '                          Value                          |                          Label                          '
    If Not @Compiled Then _ArrayDisplay($aOptionsList, '$aOptionsList, CurrentValue = ' & $sCurrentValue, '', 0, Default, $s_Header)

    If $sPrinterName = Default Then
        #TODO @Zul ===> Close the GUI .... "chrome://print"
        Return $aOptionsList
    EndIf

    Local $a_Printer[] = [$sPrinterName]
    Local $v_Ret = _WD_ElementSelectAction($sSession, $sSelectElement, "MULTISELECT", $a_Printer)
    If @error Then Return SetError(@error, @extended, $v_Ret)

    #TODO @Zul ===> Click the PRINT button
    #TODO @Zul ===> Close the GUI .... "chrome://print"
EndFunc   ;==>_WD_ChromePrintingGUI

Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

    _WD_Startup()

;~  Local $sCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"]}}}}'
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    Local $sCapabilities = _WD_CapabilitiesGet()

    Local $sSession = _WD_CreateSession($sCapabilities)
    If @error Then Return SetError(@error, @extended, '')
    _WD_ConsoleVisible(False)
    Return $sSession
EndFunc   ;==>SetupChrome

 

Edited by mLipok
small fixes in the code

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

@Zul please provide solution to this 3 #TODO's

#TODO @Zul ===> Close the GUI .... "chrome://print"
    #TODO @Zul ===> Click the PRINT button
    #TODO @Zul ===> Close the GUI .... "chrome://print"

 

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 changed the title to WebDriver UDF (W3C compliant version) - 07/29/2022
  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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