@yamaxzira

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

SeleniumでOutlookの添付ファイルを追加する方法

解決したいこと

SeleniumVBAでOutlookのWEB版を操作しようとしています。
その中で添付ファイルを追加しようとするとエラーが出てしまい追加することができません。
どなたか解決方法をご存じの方がいらっしゃいましたらご教授ください。

発生している問題・エラー

エラー内容:
CssSelecterで"input[type='file']"を指定しているのですが、恐らくこのCssがメール本文に画像を貼り付ける要素のためテキストファイルが添付できないのだと思います。

出ているエラーメッセージ:
「次のファイルは、サポートされている種類の画像ファイルではないため、挿入されませんでした。: sample.txt。サポートされている画像ファイルの種類は、.png、gif、.bmp、.jpg、.jpe、.jfif、.jpegです。」

outlookerror.jpg

該当するソースコード

VBA&SeleniumVBAを使用しています。

下記のプログラムの
attachfile.SendKeys "C:\Users****\Desktop\sample.txt"
の部分で発生します。

--- プログラム ---------------------------------------------
Dim driver As SeleniumVBA.WebDriver
Dim keys As SeleniumVBA.WebKeyboard
Dim elm As WebElement

Set driver = SeleniumVBA.New_WebDriver
Set keys = SeleniumVBA.New_WebKeyboard

With driver
.StartEdge
.OpenBrowser

.NavigateTo "https://outlook.com/owa/technopro.com"

.Wait 5000
Set elm = .FindElement(By.CssSelector, "button[aria-label='新規メール']")
elm.Click

.Wait 3000

Dim attachfile As WebElement

Set attachfile = Nothing
Set attachfile = .FindElement(By.CssSelector, "input[type='file']")
attachfile.SendKeys "C:\Users\yoshi\Desktop\sample.txt"	' ←ここでエラー発生します。

End With

挿入→添付ファイルタグを表示させてみても、別のinput[type='file']も見つからず。。。

0 likes

1Answer

自分のOWA環境ですと、

scr1.png scr2.png scr3.png

「新規メール」→「挿入」→「添付ファイル」→「このコンピュータから選択」をクリックすると、「ファイルを開くダイアログ」が表示されます。
このダイアログへの (添付ファイルの) パスの入力は、Seleniumでは出来ないと思います。

どういう入力を想定されているのか、質問者さんのスクショを添付することは可能でしょうか。

0Like

Your answer might help someone💌