Webページ内のテキストボックスやパスワードボックスへ値を反映する方法は以前ご紹介しました。
単なる文字の反映だけでなく、EnterキーやTabキーなどの特殊キーを反映することも可能です。
EnterキーやTabキーなどの特殊キーを反映するサンプルコード
'■ブラウザに対してSendKey
driver.SendKeys Keys.Tab 'TABキーを押下
driver.SendKeys Keys.Enter 'Enterキーを押下
driver.SendKeys Keys.Space 'Spaceキーを押下
'■要素にてSendKey
driver.FindElementById("userID").SendKeys Keys.Enter
Keyの一覧(よく使うのは太字)
| Tab | Add | F1 | NumPad0 | PageDown | Pause |
| Enter | Cancel | F2 | NumPad1 | PageUp | Return |
| Backspace | clear | F3 | NumPad2 | Up | LeftAlt |
| Control | Command | F4 | NumPad3 | Down | LeftControl |
| Space | Decimal | F5 | NumPad4 | Right | LeftShift |
| Shift | Delete | F6 | NumPad5 | Left | Meta |
| Alt | Divide | F7 | NumPad6 | ArrowDown | Multiply |
| End | Equal | F8 | NumPad7 | ArrowLeft | Null |
| Escape | Semicolon | F9 | NumPad8 | ArrowRight | Help |
| Home | Separator | F10 | NumPad9 | ArrowUp | |
| Insert | Subtract | F11 | |||
| F12 |
注意点
- VBAのSendKeysとSeleniumのSendKeysは別物です。(最前面になくてもキーは送られます。)
- ただし、画面上に見えていないとエラーになる場合もある為、ウィンドウ最大化推奨です。
- Ctri + A などの全選択やコピー、ペーストはKeyboard.KeyDownメソッドを使います。
SeleniumBasicについて
Internet Explorer11 のサポート期限が2022年6月までと、スクレイピング自体入れ替えていく必要があります。
今一番スムーズなのはSeleniumBasicを使用したスクレイピングと考えます。
但し、VBAでのネット記事は少なく困っている方も多いと思います。
弊社で代行開発も可能ですので、お気軽にご用命ください。



コメント