按钮使用powershell单击网站

问题描述 投票:1回答:1

我正在向网站添加用户ID和密码并尝试登录网站。在下面的代码我无法点击登录按钮我尝试点击提交但无法点击。谁能帮帮我吗

$username = "abcd" 
$password = "abc" 
$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.navigate("https://wss.mahadiscom.in/wss/wss?uiActionName=getCustAccountLogin") 
while($ie.ReadyState -ne 4) {start-sleep -m 100} 
$ie.document.getElementById("loginId").value= "$username" 
$ie.document.getElementById("password").value = "$password" 
$fs = $ie.document.getElementById("loginButton")
$fs.click()
html powershell
1个回答
1
投票

而不是本机getElementById方法,使用IHTMLDocument3_getElementById

$username="myname"
$password="mypass"
$url = "http://wss.mahadiscom.in/wss/wss?uiActionName=getCustAccountLogin"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.navigate($url)
while($ie.Busy) { Start-Sleep -Milliseconds 100 }
$ie.document.IHTMLDocument3_getElementById("loginId").value = $username
$ie.document.IHTMLDocument3_getElementById("password").value = $password
$ie.document.IHTMLDocument3_getElementById("loginButton").click()

它将显示an alert说“登录名和密码组合不正确。”。

它正在我的机器上运行IE11和WIN10。上面的代码有3个重要的变化:

  • 使用http而不是https,因为IE尝试该网站的时候该网站的证书问题。
  • 检查IE的Busy属性以检查IE是否正忙,然后等待它。
  • 使用IHTMLDocument3_getElementById而不是getElementById
© www.soinside.com 2019 - 2024. All rights reserved.