Website Login using Powershell - Click method missing - powershell

I'm trying to automate the way I login to my amazon account. Currently, I'm stuck on not being able to automate left-click on continue button after entering username.
#Here's my code:
$username = "1#2.com"
$password = "test123"
$ie = New-Object -ComObject InternetExplorer.Application;
$ie.visible=$true
$ie.navigate("https://www.amazon.com/ap/signin")
while($ie.Busy) { Start-Sleep -seconds 5 }
($ie.document.getElementById("ap_email") |select -first 1).value = $username
Start-Sleep -seconds 5
while($ie.Busy) { Start-Sleep -seconds 5 }
$continueButton = $ie.document.getElementById("continue").Click()
Write-Output Script_Complete.
pause
$ie.quit()

What about something like this?
$username = "username"
$password = "password"
$ie = New-Object -com "InternetExplorer.Application"
$ie.visible=$true
$ie.navigate("https://login.amazon.com/agreement")
while($ie.Busy) { Start-Sleep -seconds 2 }
($ie.document.getElementById("ap_email") |select -first 1).value = $username
($ie.document.getElementById("ap_password") |select -first 1).value = $password
while($ie.Busy) { Start-Sleep -seconds 2 }
$continueButton = $ie.document.getElementById("signInSubmit")
$continueButton.Click()
Write-Output Script_Complete.
pause
$ie.quit()

Related

EI click on submit button from powershell

I'm having trouble with submitting the form, the button doesn't have an ID or anything I can use or know how to use. Here is the code:
$url = "https://www.confessout.com/hi"
$message="anonymous message"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
while ($ie.Busy -eq $true) {Start-Sleep -Milliseconds 1000}
$ie.Document.getElementById("message").value = $message
Start-Sleep -Milliseconds 1000
$ie.Document.getElementByClassName('special big')[0].click
Start-Sleep -Milliseconds 10000
$ie.quit

Check if login failed

I have the following code, which logs into a site that I use frequently:
param(
[string]$interval
)
function Refresh-WebPages {
"Neptun refresh every $interval seconds."
"press any key to exit."
$shell = New-Object -ComObject Shell.Application
do {
Start-Sleep -Seconds $interval
'Refreshing'
$shell.Windows() |
Where-Object { $_.Document.url } |
ForEach-Object { $_.Refresh() }
} until ( [System.Console]::KeyAvailable )
[System.Console]::ReadKey($true) | Out-Null
}
$username = "asd";
$SecureString = Read-Host "password" -AsSecureString;
$BSTR =
[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString);
$PlainPassword =
[System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)
$IE=new-object -com internetexplorer.application;
$IE.navigate2("https://hallgato.neptun.elte.hu/login.aspx");
$IE.visible=$true;
While ($IE.Busy -eq $true) {Start-Sleep -Milliseconds 500}
$IE.Document.getElementById('user').value = "$username";
$IE.Document.getElementById('pwd').value = "$PlainPassword";
($IE.document.getElementById('btnSubmit') |select -first 1).click();
Refresh-WebPages -interval
I want to check if the login have failed or succeeded. Can I check if the URL is different somehow?

Website UN and PW Automation getting into website

What I am trying to do is automate a login for a specific website. The only thing I am having trouble with is figuring out how to make it enter into the website once it populates my UN and PW.
How do I make this script advance into the website?
$username = "XXXX";
$password = "XXX:)";
$loginUrl = "https://example.com";
$iterator = 1;
#initialize browser
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($loginUrl);
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; } #wait for browser idle
($ie.document.getElementsByName("username") |select -first 1).value = $username;
($ie.document.getElementsByName("password") |select -first 1).value = $password;
($ie.document.getElementsByName("login") |select -first 1).click();
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; } #wait for browser idle

login into a web page using powershell

I need to log on to a web page with credentials from the get-credential window. But I am getting error- Property 'Value' cannot be found on this object; make sure it exists and is settable.I have provided my powershell source code here..
$url = "ameriprisestage.service-now.com/"
$cred = Get-Credential
$username = $cred.username
$username = $username.Replace("\", "")
$password = $cred.GetNetworkCredential().password
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
while ($ie.ReadyState -ne 4 -or $ie.Busy)
{
start-sleep -milliseconds 100
}
#$uname=$ie.Document.getElementsByTagName("input")
#$unameBox=$uname | where { $_.name -eq "user_name" }
$unameBox=$ie.Document.getElementById("user_name")
$unameBox.value = $username
$pass=$ie.Document.getElementsByTagName("input") | ? { $_.id -eq "user_password" }
$pass.value = $password
$pass.select
$buttn=$ie.Document.getElementsByTagName("button") | ? { $_.id -eq "sysverb_login" }
$buttn.click()
while($ie.busy) {
Start-sleep 1;
}
There are multiple windows in the web page. Try to redirect it to the relevant window.
cd HKCU:\"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
set-itemproperty . ProxyEnable 1
$url = "https://ameriprisestage.service-now.com/"
#function call
#$cred = Get-Credential
$username = "asset_tester02"
$username = "asset_tester02"
$password = "tester02"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
while ($ie.Busy -eq $true)
{
Start-Sleep 1;
}
$usr=$ie.document.getElementbyID("gsft_main").contentWindow.document.getElementbyID("user_name").value=$username
$pass=$ie.document.getElementbyID("gsft_main").contentWindow.document.getElementById("user_password").value= $password
$buttn=$ie.document.getElementbyID("gsft_main").contentWindow.document.getElementById("sysverb_login").click()

searching a string using powershell i a web page

I need to validate the username and password of this site. When I type invalid password it should check the page for string 'invalid email'. The message fail to login should be displayed. But 'success' is being displayed.? What is the mistake?
$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)
Whilst I generally agree with #Alexander Obersht, you are only one step away from success. By creating $webClient = new-object System.Net.WebClient you establish another session to the website, when in fact you should be polling your current session inside $ie object.
Try this:
$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"
}
I also changed your match to Invalid mail.