# バッググラウンド実行でのChromeの印刷について

**URL:** <https://forum.uipath.com/t/chrome/564905>\
**Category:** フォーラム\
**Tags:** background-automation, chrome, pdf, studiox\
**Created:** [July 20, 2023, 3:29am UTC](https://forum.uipath.com/t/chrome/564905 "2023-07-20T03:29:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 3:29am UTC](https://forum.uipath.com/t/chrome/564905/1 "2023-07-20T03:29:56Z")

</div>

いつもお世話になっております。

ChromeにてWEBページの画面をPDF保存するようにしたいと思っています。当初[キーボード ショートカットキー]で印刷画面を立ち上げて実行を想定していたのですが、ロボットをバッググラウンドで動かす為、該当アクティビティが使えないと判明しました。

その為、クリックでChromeの①「…（設定）」→②「印刷…」を選択するように変更したのですが、①は上手くいっているのですが、②の段階で設定の画面がすぐに消えてしまっていて要素が抽出できない状態です。

画像での抽出や①の実行後の待機時間を変えたのですが、いずれも結果は同じでした。

アクティビティに特にこだわりはないのですが、どうにかしてバッググラウンドで印刷画面にたどり着く方法はないでしょうか？よろしくお願いいたします。

---

<div class="post-metadata">

**Author:** ![rlgandu](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/rlgandu/32/488436_2.png) [@rlgandu](https://forum.uipath.com/u/rlgandu)\
**Post date:** [July 20, 2023, 3:43am UTC](https://forum.uipath.com/t/chrome/564905/2 "2023-07-20T03:43:16Z")

</div>

> [@y.c](#):
>
> I would like to save the screen of the web page as a PDF in Chrome. Initially, I was supposed to launch the print screen with [keyboard shortcut key] and execute it, but it turned out that the activity could not be used because the robot was running in the background.
> 
> Therefore, I changed it to select Chrome’s ① “… (Settings)” → ② “Print…” by clicking.
> 
> I changed the image extraction and the waiting time after executing ①, but the results were the same.
> 
> I’m not particular about the activity, but is there a way to somehow get to the print screen in the background? Thank you.

@y.c  
Instead of trying to click through the settings to access the Print dialog, you can use the “Send Hotkey” activity to send the keyboard shortcut for printing in Chrome (e.g., `Ctrl+P` for Windows or `Cmd+P` for Mac). This will open the Print dialog.

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [July 20, 2023, 3:43am UTC](https://forum.uipath.com/t/chrome/564905/3 "2023-07-20T03:43:22Z")

</div>

こんにちは

手元の環境では問題なく指定できますが、ChromeのバージョンとUiAutomationバージョン共有可能でしょうか？

 ![image](https://global.discourse-cdn.com/uipath/original/4X/8/a/3/8a3c48305eec084d96039e92b3970c8198be7ba5.png)

> どうにかしてバッググラウンドで

これどのような意味でしょうか？  
UiPathのプロセスをバックグラウンドプロセスにしているということでしょうか？  
あるいはChromeの画面がフォアグラウンドにないという意味でしょうか？

---

<div class="post-metadata">

**Author:** ![pravallikapaluri](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/pravallikapaluri/32/484755_2.png) [@pravallikapaluri](https://forum.uipath.com/u/pravallikapaluri)\
**Post date:** [July 20, 2023, 3:43am UTC](https://forum.uipath.com/t/chrome/564905/4 "2023-07-20T03:43:56Z")

</div>

Hi @y.c

1. Use the “Open Browser” activity to open the web page in Chrome.
2. Use the “Send Hotkey” activity to simulate pressing the keyboard shortcut to bring up the Print dialog. For example, the keyboard shortcut for Print is usually `Ctrl + P`.
3. After sending the hotkey, you may need to wait for a short period to allow the Print dialog to appear. You can use the **“Delay” or “Element Exists” activity** to wait until the Print dialog is visible.
4. Once the Print dialog is visible, use the “Click” activity to click on the “Print” button within the dialog to save the page as a PDF.
5. You may need to specify the file path and name where the PDF should be saved. You can use the “Type Into” activity to enter the file path into the appropriate field in the Print dialog.
6. After clicking “Print,” the PDF should be generated and saved at the specified location.

---

<div class="post-metadata">

**Author:** ![minami](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/minami/32/176649_2.png) [@minami](https://forum.uipath.com/u/minami)\
**Post date:** [July 20, 2023, 3:48am UTC](https://forum.uipath.com/t/chrome/564905/5 "2023-07-20T03:48:11Z")

</div>

ご本人から返答あるでしょうが、画面なしの状態での実行のことを言ってるのではないでしょうか  
[https://docs.uipath.com/ja/studio/standalone/2022.10/user-guide/background-process](https://docs.uipath.com/ja/studio/standalone/2022.10/user-guide/background-process)  
ただ、これだとクリックも駄目っぽいので、別のことを言ってるのかも・・

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 4:31am UTC](https://forum.uipath.com/t/chrome/564905/6 "2023-07-20T04:31:28Z")

</div>

> [@rlgandu](#):
>
> Instead of trying to click through the settings to access the Print dialog, you can use the “Send Hotkey” activity to send the keyboard shortcut for printing in Chrome (e.g., `Ctrl+P` for Windows or `Cmd+P` for Mac). This will open the Print dialog.

Thanks for your cooperation. Hotkeys are not available in the background, so I’m looking for other ways.

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 4:32am UTC](https://forum.uipath.com/t/chrome/564905/7 "2023-07-20T04:32:25Z")

</div>

Thanks for your cooperation. Hotkeys are not available in the background, so I’m looking for other ways.

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 4:49am UTC](https://forum.uipath.com/t/chrome/564905/8 "2023-07-20T04:49:39Z")

</div>

Yoichiさん、いつもお世話になっております。ご回答ありがとうございます。

ロボットの実行ですが、タスクスケジューラでbat起動しています。本来 推奨されていないのは存じていますが、Orchestratorが導入してもらえず。。。また、環境としては、専用PCにリモートで入って開発→タスクスケジューラで自動実行しているので、実際の運用時はバッググラウンドでの実行が前提となってしまいます。

ご指摘の通り、要素自体は取得できているっぽいのですが、デバックで動かすと、①まではいくのですが、②の段階の前に設定画面が消えてしまい、要素が見つかりませんでした、というエラーで処理が終了してしまいます。

Chromeは114.0.5735.201（Official Build） （64 ビット）、UiAutomation.Activitiesは23.4.7です。

---

<div class="post-metadata">

**Author:** ![minami](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/minami/32/176649_2.png) [@minami](https://forum.uipath.com/u/minami)\
**Post date:** [July 20, 2023, 4:53am UTC](https://forum.uipath.com/t/chrome/564905/9 "2023-07-20T04:53:05Z")

</div>

もしかしたらHDMIのダミープラグを指すとか、モニタをつなげるとか、ノートPCであれば画面を閉じずに開いたままにしておくとかが解決策になるのではないかと思われます。  
PC上で画面がないと認識されているとこのような振る舞いになることがあります。

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 4:53am UTC](https://forum.uipath.com/t/chrome/564905/10 "2023-07-20T04:53:11Z")

</div>

minamiさん、ありがとうございます。  
バッググラウンドプロセスというのがあるのですね、お恥ずかしながら初めて知りました。

1つ前の投稿の通り、現在タスクスケジューラでバッチを自動実行させているため、バッググラウンドでの操作になっています。PCは開発等で使用していない時はロック状態になっています。

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 4:54am UTC](https://forum.uipath.com/t/chrome/564905/11 "2023-07-20T04:54:25Z")

</div>

PCは確かディスプレイはなかったです。手元になくオフィスに置いてあるので、リモートで入って操作しています。

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 4:56am UTC](https://forum.uipath.com/t/chrome/564905/12 "2023-07-20T04:56:24Z")

</div>

参考になるか分からないのですが、デバックでエラー終了した際の画面とエラー内容を転記しました。何故かエラーで終了すると謎のワークフローが出現して、毎回Studioを立ち上げ直し→プロジェクトを開き直してます。そういう仕様なのでしょうか？？  
[エラー内容.txt](https://forum.uipath.com/uploads/short-url/xONmKGgH5IAysEpYutl9uoqydq5.txt) (4.6 KB)

 ![キャプチャ](https://global.discourse-cdn.com/uipath/original/4X/a/c/4/ac43fadc10b2c21064daf289ca63785d3649404f.jpeg)  
 ![キャプチャ2](https://global.discourse-cdn.com/uipath/original/4X/c/5/3/c5355c885fa4dd642aac069f5f9dbbd0a2ac30c1.jpeg)

---

<div class="post-metadata">

**Author:** ![minami](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/minami/32/176649_2.png) [@minami](https://forum.uipath.com/u/minami)\
**Post date:** [July 20, 2023, 4:57am UTC](https://forum.uipath.com/t/chrome/564905/13 "2023-07-20T04:57:05Z")

</div>

ではそれが原因の可能性があります  
可能であればモニタをつないで試してみてください。  
リモートでつないだまま、最小化せずに動かしてみるでもよいとは思いますが・・

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [July 20, 2023, 5:35am UTC](https://forum.uipath.com/t/chrome/564905/14 "2023-07-20T05:35:01Z")

</div>

> また、環境としては、専用PCにリモートで入って開発→タスクスケジューラで自動実行しているので、実際の運用時はバッググラウンドでの実行が前提となってしまいます。

ユーザーがログインしていない状態で、タスクスケジューラーで起動しているということでしょうか？  
そうであれば、有効なインタラクティブセッションが存在しないので、SimulateやChromeAPI以外の入力操作や、HardwareEventレベルのUI操作はできないのではないかと思います。

> ご指摘の通り、要素自体は取得できているっぽいのですが、デバックで動かすと、①まではいくのですが、②の段階の前に設定画面が消えてしまい、要素が見つかりませんでした、というエラーで処理が終了してしまいます。

これはリモートデスクトップで画面が描画されている状態での現象でしょうか？  
クリックの入力モードは何になっていますでしょうか？  
もしHardwareEventになっているようでしたらSimulateを試してみてもらえますでしょうか？

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 5:43am UTC](https://forum.uipath.com/t/chrome/564905/15 "2023-07-20T05:43:55Z")

</div>

ありがとうございます。  
共有端末なので、その辺りの運用を許容していいただけるか社内で相談してみます。

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 6:50am UTC](https://forum.uipath.com/t/chrome/564905/16 "2023-07-20T06:50:02Z")

</div>

専用アカウントでログインした状態ですが、人が操作していない間はロック状態になっています。  
先ほど、全て「シミュレート」にしたところ、デバックでは動くようになりました！リモートデスクトップで画面が描画されている状態です。

ただ、タスクスケジューラで自動実行すると、今度は印刷画面で【保存】ボタンの「要素が見つからない」で止まってしまいます。ただ、止まった画面を見る限り、印刷画面まではきていて、「保存」ボタンも明らかに表示されているのですが・・・。

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [July 20, 2023, 6:57am UTC](https://forum.uipath.com/t/chrome/564905/17 "2023-07-20T06:57:12Z")

</div>

> [@y.c](#):
>
> ただ、タスクスケジューラで自動実行すると、今度は印刷画面で【保存】ボタンの「要素が見つからない」で止まってしまいます。ただ、止まった画面を見る限り、印刷画面まではきていて、「保存」ボタンも明らかに表示されているのですが・・・。

こちらは、画面が操作可能状態でしょうか？あるいはロック状態でしょうか？後者の場合はいろいろ制約が出てくると思いますが．．．．

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 8:20am UTC](https://forum.uipath.com/t/chrome/564905/18 "2023-07-20T08:20:01Z")

</div>

ロック状態です。。。  
基本、本番運用時はタスクスケジューラで自動実行を前提としているので、このロック状態で動いてくれるように作れれば…と思ってます。すでに作ってある部分は「シミュレート」で動いているので、なぜここだけ動かないのか分からないのですが。

---

<div class="post-metadata">

**Author:** ![Yoichi](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/yoichi/32/523754_2.png) [@Yoichi](https://forum.uipath.com/u/Yoichi)\
**Post date:** [July 20, 2023, 8:48am UTC](https://forum.uipath.com/t/chrome/564905/19 "2023-07-20T08:48:01Z")

</div>

上述しましたが、ロック状態では有効なインタラクティブセッションが存在しませんので、基本的にUI操作は避けた方が良いですし、動作も保証されないと思います。

ワークアラウンドとしては例えばコマンドで

```
chrome.exe --headless --print-to-pdf=保存ファイル名 対象URL

```

とすれば、PDF出力できる場合もあります。（途中認証が入ると難しいかもしれません）

> タスクスケジューラで自動実行を前提

こちら使用許諾の面で大丈夫でしょうか．．．．

---

<div class="post-metadata">

**Author:** ![y.c](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/y.c/32/376238_2.png) [@y.c](https://forum.uipath.com/u/y.c)\
**Post date:** [July 20, 2023, 9:19am UTC](https://forum.uipath.com/t/chrome/564905/20 "2023-07-20T09:19:55Z")

</div>

ありがとうございます。  
やはり上記状態では難しそうですね、実行方法含めて改めて検討してみます。  
コマンドも試してみます、大変助かりました。
