PowerShellからWatiNを利用
ポイント
- WatiN.Core.dllは、Add-Type -Path で読み込む。
- WatiN.Core.Findクラスの利用は、
[Watin.Core.Find]::ByName("fmInput2") [Watin.Core.Find]::ByIndex(1)
のように行う。
PowerShell用コード
# Set WatiN.Core.dll Add-Type -Path "C:\Users\mikihiro\Documents\Visual Studio 2010\Projects\WatiNStudy\WatiNStudy\bin\Debug\WatiN.Core.dll" # new InternetExplorer $ie = New-Object WatiN.Core.IE $ie.GoTo("http://www.moderns.co.jp/trade/devtest/index.html") $elem = [Watin.Core.Find]::By("name","fmInput1") $ie.TextField($elem).value = "test1" $ie.TextField([Watin.Core.Find]::ByName("fmInput2")).value = "test2" $ie.CheckBox([Watin.Core.Find]::ByName("CB3")).Checked = $true # CheckBoxのValueが"C"なのは複数あるが、そのうち最初のCheckBoxがチェックされる。 $ie.CheckBox([Watin.Core.Find]::ByValue("C")).Checked = $true # Group3の2番目。.Andで繋げることができる。 $ie.RadioButton([Watin.Core.Find]::ByName("Group3").And([Watin.Core.Find]::ByIndex(1))).Checked = $true $sel = $ie.SelectList([Watin.Core.Find]::By("name","DropDown")) #$sel.Exists #$sel | Get-Member -Type Method #$sel.Option([Watin.Core.Find]::ByValue("2")).Select() $sel.Option([Watin.Core.Find]::ByText("選択肢2")).Select() # 「開発用フォーム入力画面」がInnerTextに含まれているので、Trueがコンソールに表示される。 $ie.ContainsText("開発用フォーム入力画面") # 最初の送信ボタンをクリック。 #$ie.Button([Watin.Core.Find]::ByValue("送信")).Click() # 2番目の送信ボタンをクリック。 #$buttons = $ie.Buttons.Filter([Watin.Core.Find]::ByValue("送信")) #$buttons.Item(1).Click()
環境
- Windows 7(64bit)
- PowerShell 2.0