eightban's memo

残しておきたい記事をまとめてみました。このブログに書いてあるドキュメントやブログで配布しているファイルの使用によって発生するいかなる損害に対してもこのブログの管理者は責任を負いません。使用する場合は自己責任のもとに使用してください。

AutoIt

AutoItでMicrosoft Edgeを動かすサンプルと前回のログイン状態を使ったサンプル

投稿日:

インストール

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)

#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()

-AutoIt

Copyright© eightban's memo , 2024 All Rights Reserved Powered by STINGER.