Not able to login on website through script

Hi,

Made a script for login on splunk website and it is running successfully without any failure or error but not able to launch internet explorer so any insight will be appreciated.

$username = “username”
$password = “password”
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$false
$ie.navigate(“The IT Search Engine | Splunk”)
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById(“username”).value= “$username”
$ie.document.getElementById(“pass”).value = “$password”
$ie.document.getElementById(“loginform”).submit()
start-sleep 20
$ie.Document.body | Out-File -FilePath c:\web.txt

Thanks
Ankit

IE will launch if you change $false to $true. Also, the page may need more time to load.

$username = "username"
$password = "password"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$True
$ie.navigate("https://login.splunk.com/index.php?module=roles&func=showloginform")
while($ie.ReadyState -ne 4) {start-sleep -Seconds 5}
$ie.document.getElementById("username").value= "$username"
$ie.document.getElementById("pass").value = "$password"
$ie.document.getElementById("loginform").submit()
start-sleep 5

thanks for the reply but when i am executing your given script by passing on username and password parameter it is showing “login error missing data- you must provide a username” (showing on splunk website) but i have already provided username and password in the script so do you have any idea for this?

Thanks in advance

I forgot you are using IE. The login element should have a click method used to click the login button. I don’t have a Splunk account to test, but this should work. I recommend using Invoke-WebRequest or Invoke-RestMethod when sites are involved.

$username = "username"
$password = "password"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$True
$ie.navigate("https://login.splunk.com/index.php?module=roles&func=showloginform")
while($ie.ReadyState -ne 4) {start-sleep -Seconds 5}
$ie.document.getElementById("username").value= "$username"
$ie.document.getElementById("pass").value = "$password"
$ie.Document.getElementById('login').click()
start-sleep 5

Thanks a ton… its work… :slight_smile: