Jump to content

Recommended Posts

Posted
  On 7/30/2022 at 9:46 PM, Danp2 said:

I was speaking in general terms from the Webdriver specs

Expand  

Thanks for clarification.

  On 7/30/2022 at 9:46 PM, Danp2 said:

Of course you can do all kinds of things with Javascript, but that was outside the scope of that discussion.

Expand  

In fact I was doing this 2 times, which speed up some of my job that I had to do.

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 4/10/2022 at 10:47 PM, CodeWriter said:

The debug flag may be helpful, but in all honesty it’s so verbose that whenever I’ve tried to look at it, it’s been like trying to find a needle in a haystack and I’m not familiar with the output so I don’t even know what the needle looks like…

Expand  

@CodeWriter please check current version of this UDF and say if now it looks to you more friendly.
As you was an inspiration to the change :)

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 7/30/2022 at 9:46 PM, Danp2 said:

 

@ZulYou may be correct. _WD_ElementOptionSelect is the correct choice, expect when a shadow root is involved.

Expand  

@Danp2 I used _WD_FindElement and  _WD_ElementAction($sSession, $divExpand, 'click'to click the "Customised" PrintScaleType <option> since a shadow-root is involved here. It worked, expanded the <iron-collapse> to expose and made the "Print Scaling factor" <input> element visible. It even set the focus (cursor) onto the input element. Then, I was able to change the input by using ElementAction "CLEAR" and "VALUE".
Thank you! 🙂

 

  On 7/30/2022 at 9:31 PM, mLipok said:

Do you have github account ?
Just fork https://github.com/Danp2/au3WebDriver and create new branch on your side.
Give us link to them. Then it will be easier to follow your changes.

Expand  

@mLipok I do not have one. If it helps, I will get round to creating one?

Edited by Zul
Posted
  On 7/28/2022 at 4:06 PM, mLipok said:

@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"

 

Expand  

I reckon using FindElement and ElementAction "click" on the "Cancel" button will close the GUI.
As for clicking the PRINT button, I am leaving that to the control of the end-user to have control over.
I would like them to glance to the left panel to check the print preview looks OK, verify the print area/margins are to their expectations, then the user decides the press "Print" button. Or if they have selected by mistake a wrong document to print, they could elect to click "Cancel" to re-select the correct document.

  On 7/28/2022 at 4:12 PM, mLipok said:

btw.
I added:

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

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

but it change browser content from google to printing GUI, thus browser content that will be printed is empty, but this should print google content.

Can anyone fix it?

 

Expand  

As for this, it nees a re-think and some help from you gurus.
So far, the code opens a Chrome temp user profile new  window that starts with URL (data:,), then it navigates to URL (chrome://print) and executes all the functions I coded to interact with the settings on the sidebar.

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)

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

    _WD_Shutdown()
EndFunc   ;==>_Example


But the interaction I need to achieve, would not be to navigate to the "chrome://print" URL myself.
The end-user uses a cloud CRM and when they initiate to print invoices/labels, the CRM software:
1) Opens a new tab with a 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

DevTools snippet for Elements tab:

<!DOCTYPE html>
<html dir="ltr" lang="en" class="">
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <meta name="color-scheme" content="light dark">
  <base href="chrome://print">
...
<head>
</body>
...
</body>
</html>

but the Sources tab have the HTML title tag as: <title>Print preview dialogue</title> instead?

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?

I have tried _WD_Attach($sSession, 'Untitled') and _WD_Attach($sSession, 'Print preview dialogue'), error says "No match".

I tried using _WD_Window($sSession, 'HANDLES') which I've read "get all window handles" but when I assigned it to an array to display, there's only a single row? (CDwindow-xxxxxxxx) with "xxxxxxx" being a long string of alphanumeric/hexadecimal characters.
Was planning to iterate through the handles to assign it to a single handle and use _WD_Window($sSession, "SWITCH", $sHWnd) to switch to the Print Dialog pop-up window using its handle? Probably a silly idea since if it's all in alphanumeric/hexadecimal, I wouldn't be able to make out which one belongs to the Print Dialog pop-up window!

Am I moving in the right direction?

Zul

Posted
  On 7/26/2022 at 1:29 PM, mLipok said:

What kind of replacement I can use for:

_IEAction($oElement, "scrollintoview", 200, 0, False)

?

 

EDIT:
Only with JavaScript ?
https://stackoverflow.com/a/20487332/5314940

?

Expand  

The JavaScript solution would be to use the scrollIntoView method: Element.scrollIntoView() - Web APIs | MDN (mozilla.org)

I'm guessing that's what IEAction does internally :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

  Reveal hidden contents
Posted

I allready did this:

Local $s_JavaScript = _
            "var element = document.querySelector('" & $s_CSSSelector & "');" & _
            "element.scrollIntoView(true);"

but it not always works as I expect.... Investigation will be performed later.

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/1/2022 at 12:38 PM, Zul said:

I have tried _WD_Attach($sSession, 'Untitled') and _WD_Attach($sSession, 'Print preview dialogue'), error says "No match".

Expand  

using browser console:

  Quote

window.location.href
'chrome-untrusted://print/8/0/print.pdf'

Expand  

 

so would you try:

_WD_Attach($sSession, 'chrome-untrusted://print/8/0/print.pdf', 'url')

or

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

 

btw. did you try this following JS to invoke printing GUI

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

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Here is my checking:

Func UserTesting() ; here you can replace the code to test your stuff before you ask on the forum
    _WD_CheckContext($sSession, False)
    If @error Then ; return if session is NOT OK
        ConsoleWrite("! ---> @error=" & @error & "  @extended=" & @extended & _
                " : _WD_CheckContext reported a problem with the session" & @CRLF)
        Return
    EndIf

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

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

    MsgBox(0, "", 1)
    _WD_Attach($sSession, 'chrome-untrusted://print/8/0/print.pdf', 'url')
    If @error Then
        ConsoleWrite("! ---> @error=" & @error & "  @extended=" & @extended & _
            " : _WD_Attach($sSession, 'chrome-untrusted://print/8/0/print.pdf', 'url')" & @CRLF)
    Else
        MsgBox(0, "", 2)
    EndIf

    _WD_Attach($sSession, 'chrome://print/', 'url')
    If @error Then
        ConsoleWrite("! ---> @error=" & @error & "  @extended=" & @extended & _
            " : _WD_Attach($sSession, 'chrome://print/', 'url')" & @CRLF)
    Else
        MsgBox(0, "", 3)
    EndIf

    MsgBox(0, "", 4)
EndFunc

I have notice that:

_WD_ExecuteScript($sSession, 'window.print()')

holds script execution, so I used:

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

but I get:

  Quote

__WD_Post ==> Webdriver Exception [10] : HTTP status = 500
_WD_ExecuteScript ==> Webdriver Exception [10] : Error occurred when trying to ExecuteScript

Expand  

 

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')

 

 

Question:
Can somebody propose any work around for using:

_WD_ExecuteScript($sSession, 'window.print()')

?

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

Here I found interesting reding about async execution with webdriver

https://stackoverflow.com/a/28057738/5314940

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)

Aftere reading here:

https://www.w3.org/TR/webdriver/#execute-async-script

  Quote
  1. Let resolvingFunctions be CreateResolvingFunctions(promise).

  2. Append resolvingFunctions.[[Resolve]] to arguments.

Expand  


I start to wonder:
Should we pass something to _WD_ExecuteScript as argument ?

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/1/2022 at 10:31 PM, Danp2 said:

P.S. Have you seen @TheDcoder's earlier post?

Expand  

yes, as I ask for support and @TheDcoder answers to me.
But I'm not as JS expert as @TheDcoder is.

So we must ask him how to properly use:

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

and we must wait for his answer.

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
  On 8/1/2022 at 10:31 PM, Danp2 said:

Let me know if you figure it out.

Expand  

ding ding....

  Reveal hidden contents

 

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

How to move the chrome window with the $sSession info? As there might be multiple chrome window with the same title. I just want to arrange those windows from webdriver scripts

Thank you

Posted

@mLipok Hi, I haven't been following the thread, but I quickly went through it, so please correct me if I missed anything.

The documentation for window.print():

  Quote

Opens the print dialog to print the current document.

If the document is still loading when this function is called, then the document will finish loading before opening the print dialog.

This method will block while the print dialog is open.

Syntax

print()

Parameters

None.

Return value

None (undefined).

Expand  

So it's just an opaque function which opens the browser's print dialog, it doesn't actually give us the interface to interact with it in any way.

And that's why you should use other methods like WD's print function to print the page instead of calling window.print(). If there is a specific reason why this needs to be called then please let me know.

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 6:23 AM, TheDcoder said:

So it's just an opaque function which opens the browser's print dialog, it doesn't actually give us the interface to interact with it in any way.

Expand  

As I showed above we are able to _WD_Attach to this window in Chrome.

  On 8/2/2022 at 6:23 AM, TheDcoder said:

And that's why you should use other methods like WD's print function to print the page instead of calling window.print(). If there is a specific reason why this needs to be called then please let me know.

Expand  

_WD_PrintToPDF() which use WD's Print function give as a result PDF binary data.
What if you want just print window content to a printer device without any third party software (for printing PDF) ?


 

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 6:23 AM, TheDcoder said:

This method will block while the print dialog is open.

Expand  

So you tries to say to me that there is no way to use JS windows.print() in async mode ?

 

btw.
Interesting reading:

https://stackoverflow.com/a/18325463/5314940
https://www.tjvantoll.com/2012/06/15/detecting-print-requests-with-javascript/

and some other findings:
https://bugs.chromium.org/p/chromium/issues/detail?id=103375

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
  On 8/2/2022 at 6:33 AM, mLipok said:

As I showed above we are able to _WD_Attach to this window in Chrome.

Expand  

Oh, that's great. I cannot comment on the print window itself as I have never looked at the internals, and I don't think it's supposed to be automated anyway.

  On 8/2/2022 at 6:33 AM, mLipok said:

What if you want just print window content to a printer device without any third party software (for printing PDF) ?

Expand  

Just like how you would attempt to print a normal PDF document. I am not a printing expert but I'm assuming Windows has APIs to tell the printer to print out a PDF.

  On 8/2/2022 at 6:35 AM, mLipok said:

So you tries to say to me that there is no way to use JS windows.print() in async mode ?

Expand  

Yes, it always blocks. Async mode is just a different method of returning a value back to the WD client, the actual code works the same in both modes, so it doesn't make any difference in this case.

In fact you'd want to use "sync" mode and execute a timer based script (setTimeout) to call window.print() so that it doesn't block your WD code.

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

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

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