機能・目的
キーボード上の特殊キーを押す。
CtrlキーやShiftキーなどを押しながら別のキーを押す複合キー入力操作
記法
|
(1)
|
.SendKeys oKey.特殊キー | ※oKeyは特殊キーを指定するために宣言したもの |
|
(2)
|
.SendKeys 同時に押すキー1,同時に押すキー2 |
使用例
|
(1)
|
用意されたテスト画面でTABとShift+TABでタブの前後移動をテストします。
'テスト用にSleep命令が使いたいので
Private Declare Sub Sleep Lib "kernel32" (ByVal ms As Long)
Sub test()
'ドライバを定義
Dim Driver As New Selenium.WebDriver
' keysを使用するために宣言
Dim oKey As New keys
'ブラウザにChromeを指定し起動
Driver.Start "chrome"
'IceProbeのテスト画面を表示
strURL = "https://www.iceprobe.net/プログラミング言語/selenium/selenium-画面操作-試験場1/"
Driver.Get strURL
'IDフィールドをクリック
Driver.FindElementByXPath("//*[@id=""form1""]").Click
Sleep 1000
'特殊キー操作タブ移動(前進)TAB
Driver.FindElementByXPath("/html/body").SendKeys oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Tab
Sleep 1000
'複合特殊キー操作 タブ移動(後退)Shift+TAB
Driver.FindElementByXPath("/html/body").SendKeys oKey.Shift, oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Shift, oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Shift, oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Shift, oKey.Tab
Sleep 1000
Driver.FindElementByXPath("/html/body").SendKeys oKey.Shift, oKey.Tab
'テスト用に一時停止します。(処理には必要ありません)
MsgBox ("テスト用に一時停止します")
End Sub
テスト画面スタートするとIDがクリックされフォーカスが移動します。 実行後1秒ごとに下方にタブ移動し、今度は上方にタブ移動して元の場所まで戻ります。
|

