インストール
Google Chrome と同じ所は下記サイトを参考
http://memo.eightban.com/autoit/autoit_chrome
WebDriver
edge://settings/help
ブラウザーと同じバージョンを入れます
https://developer.microsoft.com/ja-jp/microsoft-edge/tools/webdriver/
AutoItフォルダへファイル入れます
サンプル
Bing にキーワードを入力し検索した件数を出すサンプルです。
前回のログイン状態を使うためにはコメントを外してください。
設定しないとプロフィールパスはテンポラリーホルダーに作成されます
;_WD_CapabilitiesAdd('args','--user-data-dir=' & $EDGE_profile)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
#include <wd_core.au3> #include <wd_capabilities.au3> #include <wd_helper.au3> Const $EDGE_profile = 'C:\Users\username\AppData\Local\Microsoft\Edge' Const $EDGE_driver = 'C:\app\AutoIt3\msedgedriver.exe' _WD_Option('Driver', $EDGE_driver) _WD_Option('DriverParams', ' --verbose --log-path=' & @ScriptDir & '\edge.log') _WD_Option('Port', 9515) _WD_CapabilitiesStartup() _WD_CapabilitiesAdd('alwaysMatch', 'ms:edgeOptions') _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation') ;_WD_CapabilitiesAdd('args','--user-data-dir=' & $EDGE_profile) ;_WD_CapabilitiesAdd('args', '--headless') Local $sCapabilities = _WD_CapabilitiesGet() Local $pid = _WD_Startup() If @error Then Msgbox(4096,"error", "Failed to start webdriver",10) Exit EndIf $session = _WD_CreateSession($sCapabilities) If @error Then MsgBox(4096, "error", "browser did not start",10) If $pid Then _WD_Shutdown() Exit EndIf Sleep(1000) _WD_Navigate($session, "https://www.bing.com") If @error Then MsgBox(4096, "error", "Could not open the specified URL. extended=" & @extended ,10) EndIf Sleep(3000) $value="A" $spath = "/html/body/div[2]/div/div[3]/main/form/div[1]/input" $element = _WD_WaitElement($session, $_WD_LOCATOR_ByXPath, $spath) _WD_SetElementValue($session, $element, $value) Sleep(3000) $spath = "/html/body/div[2]/div/div[3]/main/form/label" $element = _WD_WaitElement($session, $_WD_LOCATOR_ByXPath, $spath) _WD_ElementAction($session, $element, 'click') Sleep(3000) $element = _WD_WaitElement($session, $_WD_LOCATOR_ByXPath, '/html/body/div[1]/main/div[1]/span[1]') If @error Then Msgbox(4096,"error", "element get failed",10) EndIf $txt = _WD_ElementAction($session, $element, "text") MsgBox(4096, "text", $txt) Sleep(3000) _WD_Window($session, "close") If $session Then _WD_DeleteSession($session) If $pid Then _WD_Shutdown() |