No meu PC, NÃO consigo usar
o comando:
uiv.browser.type('${KEY_CTRL+KEY_P}');
uiv.sleep('2s');
uiv.browser.type('${KEY_ENTER}');
Não esta dando erro, apenas não acontece nada e o fluxo segue normal para os próximos passos.
No meu PC, NÃO consigo usar
o comando:
uiv.browser.type('${KEY_CTRL+KEY_P}');
uiv.sleep('2s');
uiv.browser.type('${KEY_ENTER}');
Não esta dando erro, apenas não acontece nada e o fluxo segue normal para os próximos passos.
Hello,
This is expected behaviour, not a problem with your PC. uiv.browser.type sends the keys to the page, inside the tab. Ctrl+P is a browser shortcut, not a page shortcut. Chrome does not run its own shortcuts (Ctrl+P, Ctrl+T, Ctrl+S, zoom with Ctrl++ and Ctrl+- …) when the key arrives that way. That is why there is no error: the key was sent, the page received it and ignored it.
There are two solutions:
1. Real operating-system keyboard (uiv.desktop.keyboard)
This needs the Ui.Vision desktop app installed. It produces a real OS keystroke, which reaches the browser and also the print dialog:
uiv.window.focus(); // bring the browser window to the front
uiv.desktop.keyboard.type('${KEY_CTRL+KEY_P}');
uiv.sleep('2s');
uiv.desktop.keyboard.type('${KEY_ENTER}');
The second step (Enter) must also be uiv.desktop.keyboard. If the destination is a real printer or “Save as PDF” with the native Windows dialog, that dialog is outside the page and uiv.browser.type never reaches it.
2. Without the desktop app: open printing from the page
This opens the same print window. To confirm it with Enter you still need the real keyboard from option 1.
uiv.evaluate('setTimeout(() => window.print(), 0)');
Rule of thumb:
(Only) For keys inside the page (fields, the site’s own shortcuts), use uiv.browser.type.
For browser shortcuts, system dialogs and other programs, use uiv.desktop.keyboard.type.