Jump to content

Recommended Posts

Posted
  On 8/2/2022 at 9:27 AM, TheDcoder said:

I'm assuming Windows has APIs to tell the printer to print out a PDF

Expand  
ShellExecute +
$SHEX_PRINT ("print") = Prints the document file specified. If "filename" is not a document file, the function will fail


but you must have intaled program like PDFReader or any other.

 

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/2/2022 at 9:41 AM, mLipok said:

but you must have intaled program like PDFReader or any other.

Expand  

Surely there's another way. How do programs like PDF reader do it?

AFAIK Printers can directly accept postscript documents (which are very also valid PDF documents) so there must be a way to tell a printer to print the file directly, perhaps after some post-processing.

And I guess you can also go the route of automating the print dialog in Chrome, but you'll have to automate it directly, window.print will not help you here.

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted
  On 8/2/2022 at 10:03 AM, TheDcoder said:

but you'll have to automate it directly, window.print will not help you here.

Expand  

I was hoping in sending CTRL+P some how via WD UDF.

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/2/2022 at 10:03 AM, TheDcoder said:

AFAIK Printers can directly accept postscript documents (which are very also valid PDF documents) so there must be a way to tell a printer to print the file directly, perhaps after some post-processing.

Expand  

As so far I found this:

https://answers.microsoft.com/en-us/windows/forum/all/how-do-i-print-postscript-file-in-windows-7/80ea6bb5-6b3c-4a2e-a020-369ada496ba0

https://www.vertopal.com/en/convert/pdf-to-ps

https://www.makeuseof.com/libreoffice-pdf-editor/

 

  On 8/2/2022 at 10:03 AM, TheDcoder said:

perhaps after some post-processing.

Expand  

yes, usually all solutions for printing PDF needs some kind of third party software.
I mean I never found direct windows solution.
The easies way is 

  On 8/2/2022 at 9:41 AM, mLipok said:
ShellExecute +
$SHEX_PRINT ("print") = Prints the document file specified. If "filename" is not a document file, the function will fail
Expand  

For this reason we are trying to make it possible to print directly from browsers to printer device, with full automatization.

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/2/2022 at 10:05 AM, mLipok said:

I was hoping in sending CTRL+P some how via WD UDF.

Expand  

Doesn't that do the same thing as calling window.print()? i.e. opening the print dialog

  On 8/2/2022 at 10:13 AM, mLipok said:

For this reason we are trying to make it possible to print directly from browsers to printer device, with full automatization.

Expand  

This will be a hard/impossible task to do with cross-browser support, so I wish you the best of luck. At-least Chrome is allowing you to attach the print window with WD for automation :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted
  On 8/2/2022 at 10:16 AM, TheDcoder said:

Doesn't that do the same thing as calling window.print()? i.e. opening the print dialog

Expand  

no

  On 8/1/2022 at 9:43 PM, mLipok said:

but when I commented:

;~  _WD_ExecuteScript($sSession, 'window.print()', Default, True)

and manually used CTRL+P

then it founds that correct attach method is:

_WD_Attach($sSession, 'chrome://print/', 'url')

 

Expand  

 

 

 

  On 8/2/2022 at 10:16 AM, TheDcoder said:

This will be a hard/impossible task to do with cross-browser support, so I wish you the best of luck.

Expand  

 

I know.

I have to check if the same code works with Edge and Opera.
 

  On 8/2/2022 at 10:16 AM, TheDcoder said:

At-least Chrome is allowing you to attach the print window with WD for automation

Expand  

and this is what I'm trying to do ... hope together with @Zul

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I wonder:
How to use JS to get element identifier the same as is returned by _WD_FindElement() ?

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)
  On 8/2/2022 at 4:39 PM, mLipok said:

How to use JS to get element identifier the same as is returned by _WD_FindElement() ?

Expand  

Can't scripts return elements which are translated into the element identifiers by the WD?

return document.body;

 

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Posted
Local $sWebDriver_ElementID =_WD_ExecuteScript($sSession, "return window.document.body;", Default, Default, $_WD_JSON_Element)
                MsgBox(0, "$sWebDriver_ElementID", $sWebDriver_ElementID)

Thanks.

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Hi Dan,

is it possible to click on a button identified with src="..." where src contains a special string to search for? I cannot use the XPath because it changes sometimes and there are many similiar ones which differ just in one number (and that changes). But I can find a string in each src="" that is unique.

Example:

<img id="content-form:favorites:1:fav-image" src="/portal/images/icons/vu/icon_german.png.xhtml" alt="" style="width: 126px; height: 96px; position: relative;" class="ui-draggable ui-draggable-handle ui-droppable">

<img id="content-form:favorites:5:fav-image" src="/portal/images/icons/vu/icon_greek.png.xhtml" alt="" style="width: 126px; height: 96px; position: relative;" class="ui-draggable ui-draggable-handle ui-droppable">
 

And I want to click on the Button that contains src="... german ...". I cannot use the :1: because next time it could be :6: or any other number.

Thanks for your help!

Edited by HJL
Posted (edited)
  On 8/3/2022 at 2:37 PM, HJL said:

is it possible to click on a button identified with src="..." where src contains a special string to search for? 

.......

<img id="content-form:favorites:1:fav-image" src="/portal/images/icons/vu/icon_german.png.xhtml" alt="" style="width: 126px; height: 96px; position: relative;" class="ui-draggable ui-draggable-handle ui-droppable">

Expand  

try this:

Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "img[src*='icon_german' AND src*='png' AND src*='xhtml']")
_WD_ElementAction($sSession, $sElement, 'CLICK')

For more information take a look here:
https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors

 

You can also use more advanced function: _WD_GetElementByRegEx()

 

 

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

@mLipok
When using browser console, it returned the belowmentioned result for me.

window.location.href
'chrome://print'

This correct attach method works for me as well.

_WD_Attach($sSession, 'chrome://print/', 'url')

 

  On 8/1/2022 at 12:38 PM, Zul said:

Question here is (instead of navigating to chrome://print on my own) how do I get to this Print Dialog pop-up window and execute all the functions I coded to interact with this Print Dialog pop-up window?

Expand  

I was then able to interact with the elements on this Chrome Print Dialog pop-up! 🙂
Some of them include:

;Success
    _WD_ChromePrintDestination($sSession, 'Save as PDF') ; Change to Brother MFC/TSC-TA210 on real deployment
    _WD_ChromePrintMoreSettings($sSession) ; Expand More Settings section
    _WD_ChromePrintPaperSize($sSession, 'A5') ; A5 (Invoices) / Label(medicine labels) / A4 (Documents)
    _WD_ChromePrintScalingType($sSession, 'Customised')
    _WD_ChromePrintScalePercent($sSession, '75') ; 75 (Invoices) / 100 (Labels)

 

  On 8/1/2022 at 9:43 PM, mLipok said:

but when I commented:

;~  _WD_ExecuteScript($sSession, 'window.print()', Default, True)

and manually used CTRL+P

Expand  

I used Send("^p") in place of the manual Ctrl+P 🙂
I know, it's a 'dirty' way of invoking. It was just to test.

Posted

Thank you all who's been very helpful and taking an interest to this little project of mine.
With the functions that we've co-written and figuring out attaching to the Chrome Print Dialog, that's attaching to a self-invoked Print Dialog, off a session that's started by the code and navigated to URL, etc.

How could I attach to a Print Dialog that's being invoked by the end-user?
From a CRM website (when they select the Print icon off the site).
The flow is as such:
The end-user uses a cloud-based CRM and when they initiate to print invoices/labels, the CRM website:
1) Opens a new tab with a image render of the invoice or label
2) Calls the famous (Ctrl+P) Chrome's Print Preview Dialogue whose window pops up on top of this new tab

I tried manually invoking this Print Dialog from the CRM website (instead of sending Ctrl-P from the code), it could not find it (No match [8])

_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:\Users\Zul\Documents\au3WebDriver-0.10.0\chrome.log"
_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--marionette-port 2828
_WD_IsLatestRelease ==> Success [0] : False
_WD_Startup: OS:    WIN_10 WIN32_NT 19044 
_WD_Startup: AutoIt:    3.3.16.0
_WD_Startup: Webdriver UDF: 0.10.0 (Update available)
_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:    --marionette-port 2828
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe" --marionette-port 2828 
_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] : b580e90d05d869800b24f1583559ee31
__WD_Get ==> Success [0] : HTTP status = 200
_WD_Window ==> Success [0] : Parameters:   Command=handles   Option=Default
__WD_Get ==> Success [0] : HTTP status = 200
_WD_Window ==> Success [0] : Parameters:   Command=window   Option=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Window ==> Success [0] : Parameters:   Command=Switch   Option={"handle":"CDwindow-F3576B3E937905BDB0C4FBD104E4E51A"}
__WD_Get ==> Success [0] : HTTP status = 200
_WD_Action ==> Success [0] : Parameters:   Command=url   Option=Default
__WD_Post ==> Success [0] : HTTP status = 200
_WD_Window ==> Success [0] : Parameters:   Command=Switch   Option={"handle":"CDwindow-F3576B3E937905BDB0C4FBD104E4E51A"}
_WD_Attach ==> No match [8] : Parameters:    Search=chrome://print/    Mode=url
! ---> @error=8  @extended=0 : _WD_Attach($sSession, 'chrome://print/', 'url')

I tried to follow the answer to WebDriver FAQ Qn#1 on connecting to a running browser instance, but tweaking the codes for Chrome instead of Firefox as advised by you, @mLipok. But wasn't really successful. The part on:

        _Testing_AttachSession($s_Chrome_Binary)
        _WD_Navigate($_MY__WD_SESSION, 'https://www.google.com/')

Returned me:

_WD_UpdateDriver ==> Success [0 / 0] : DriverCurrent = 103.0.5060.134 : DriverLatest = 103.0.5060.134
_WD_Option ==> Success [0] : Parameters:   Option=Driver   Value=chromedriver.exe
_WD_Option ==> Success [0] : Parameters:   Option=Port   Value=9515
_WD_Option ==> Success [0] : Parameters:   Option=DriverParams   Value=--log trace --marionette-port 2828 --connect-existing
_WD_IsLatestRelease ==> Success [0] : False
_WD_Startup: OS:    WIN_10 WIN32_NT 19044 
_WD_Startup: AutoIt:    3.3.16.0
_WD_Startup: Webdriver UDF: 0.10.0 (Update available)
_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:    --log trace --marionette-port 2828 --connect-existing
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe" --log trace --marionette-port 2828 --connect-existing 
_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_CapabilitiesAdd ==> Success [0] : Successfully added capability
__WD_Post ==> Success [0] : HTTP status = 200
_WD_CreateSession ==> Success [0] : 834809388c103bbe0c5a4cc4b5364037
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_Navigate ==> Invalid session ID [15] : Parameters:   URL=https://www.google.com/
__WD_Post ==> Invalid session ID [15] : HTTP status = 404
_WD_Action ==> Invalid session ID [15] : Parameters:   Command=REFRESH   Option=Default
__WD_Delete ==> Success [0] : HTTP status = 200
_WD_DeleteSession ==> Success [0] : WebDriver session deleted


Maybe, I'll find some time tomorrow to draw up the algorithm flowchart of this little project to illustrate things better. That could give a better idea.

Thanks once again.

Zul

Posted
  On 8/3/2022 at 7:48 PM, Zul said:

Maybe, I'll find some time tomorrow to draw up the algorithm flowchart of this little project to illustrate things better. That could give a better idea.

Expand  

So we are waiting.

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 8/3/2022 at 8:23 PM, mLipok said:

So we are waiting.

Expand  

Thanks for waiting. I'll attach the flowchart here as PDF. 🙂 

I've managed to code the area marked by green dotted lines - - - "Completed"


Struggling with the SetupChrome() to startup, connecting to a running browser instance and utilizing an existing user profile.
- Running browser instance = tab where the CMS website is open
- Or if it isn't necessary, running browser instance = directly to the Print Dialog pop-up window when the CMS invokes it.

And WD_Attach to the Print Dialog invoked by the CMS.

The GUI, I was thinking of it more for later.

If it is too complicated, it could also be replaced by an assigned HotKey, which waits for a HotKey pressed each time, executes codes, then loops and return to waiting for the next HotKey press trigger?

Thank you.

Zul

CMS Printing Automation Flowchart.pdfFetching info...

Posted (edited)

So as far as I understand the situation:
When somebody click "Print Invoice" on the main TAB then CMS opens new TAB and this means that your main TAB is not blocked.

Does this also means that your AutoIt WebDriver automation also is not blocked when the new TAB appears (I mean after AutoIt script click "Print Invoice" ) ?


btw.
Awesome flowchart PDF. How did you do it?

edit:
please read also Please remember: "AutoIt"..... *

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

hello,

 

i break my mind with the webdriver, i need your help.

what is the alternatives:

1.StringInStr

2._IEPropertyGet

3._IEGetObjById

4._IELoadWait

5._IEBodyReadHTML

6._IEAction($oIE, "selectall") , _IEAction($oIE, "copy")

7._IEFormElementSetValue

 

thanks!!

 

Posted (edited)

Take a look at our WD wiki topic.

There is section about migrating from IE ro WD

EDIT:
https://www.autoitscript.com/wiki/WebDriver#Translate_IE_UDF_to_WebDriver

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:

  Reveal hidden contents

Signature last update: 2023-04-24

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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