您好,登錄后才能下訂單哦!
心血來(lái)潮,簡(jiǎn)單的測(cè)試一下Powershell的IE自動(dòng)化。
圖像界面:
訪問(wèn)一個(gè)內(nèi)部的https網(wǎng)頁(yè),首先會(huì)彈出一個(gè)ssl信任證書(shū)的警告頁(yè)面,點(diǎn)擊確認(rèn)之后進(jìn)入登錄界面,輸入用戶名和密碼點(diǎn)擊登錄。
代碼如下:
#輸入url,用戶名和密碼 $Url = "https://10.2.1.18/admin/login.jsp” $Username=”admin” $Password=”ABCD” #創(chuàng)建一個(gè)IE對(duì)象,可視,加載 $IE = New-Object -com internetexplorer.application; $IE.visible = $true; $IE.navigate($url); #等待完全加載 while ($IE.Busy -eq $true) { Start-Sleep -s 2; } #通過(guò)url判斷,如果是ssl警告界面,那么點(diǎn)擊<a>標(biāo)簽繼續(xù)下一頁(yè) if($IE.Document.url -match "invalidcert"){ Write-Host "Bypass SSL Error Page" -ForegroundColor Cyan $link=$IE.Document.getElementsByTagName('A') | Where-Object{$_.id -eq 'overridelink'} Write-Host "Loading Login page " -ForegroundColor Cyan $link.click() } #等待完全加載 while ($IE.Busy -eq $true) { Start-Sleep -s 2; } #通過(guò)html的標(biāo)簽id來(lái)選擇對(duì)應(yīng)的元素,當(dāng)然根據(jù)實(shí)際情況可以選擇class,name或者tagname;然后給value賦值 $IE.Document.getElementById(“dijit_form_TextBox_0”).value = $Username $IE.Document.getElementByID(“dijit_form_TextBox_1”).value=$Password #最后在按鈕上執(zhí)行點(diǎn)擊事件 $IE.Document.getElementById(“l(fā)oginPage_loginSubmit_label”).Click() Write-Host "Submit the login" -ForegroundColor Cyan
登錄成功
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。