我需要验证这个网站的用户名和密码。当我输入无效密码时,它应该检查页面中字符串“无效电子邮件”。应该显示无法登录的消息。但是“成功”正在被展示出来。这是什么错误?
$url = "https://www.jabong.com/customer/account/login/"
$cred = Get-Credential #Read credentials
$username = $cred.username
$username = $username.Replace("\", "")
$password = $cred.GetNetworkCredential().password
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
while ($ie.Busy -eq $true)
{
Start-Sleep 1;
}
$ie.Document.getElementById("LoginForm_email").value = $username
$ie.Document.getElementByID("LoginForm_password").value=$password
$ie.Document.getElementByID("qa-login-button").Click();
while($ie.busy) {sleep 1}
$webClient = new-object System.Net.WebClient
$webClient.Headers.Add("user-agent", "PowerShell Script")
$output = $webClient.DownloadString("https://www.jabong.com/customer/account/login/")
if ($output -like "*Invalid mailid*") {
"login failed"
} else {
"success"
}
sleep(300)发布于 2014-06-25 09:59:04
虽然我总体上同意亚历山大·奥伯希特的观点,但你离成功只有一步之遥。通过创建$webClient = new-object System.Net.WebClient,您可以为网站建立另一个会话,而实际上您应该在$ie对象中轮询当前会话。
试试这个:
$url = "https://www.jabong.com/customer/account/login/"
$cred = Get-Credential #Read credentials
$username = $cred.username
$username = $username.Replace("\", "")
$password = $cred.GetNetworkCredential().password
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
while ($ie.Busy -eq $true)
{
Start-Sleep 1;
}
$ie.Document.getElementById("LoginForm_email").value = $username
$ie.Document.getElementByID("LoginForm_password").value=$password
$ie.Document.getElementByID("qa-login-button").Click();
while($ie.busy) {sleep 1}
$output = $ie.Document.Body.innerHTML
if ($output -like "*Invalid mail*") {
"login failed"
} else {
"success"
}我还把你的对手改成了Invalid mail。
https://stackoverflow.com/questions/24389753
复制相似问题