简体   繁体   English

调试Powershell登录网页脚本

[英]debugging powershell login webpage script

I have this poweshell script - which opens up the webpage - however the idea is that it would log into the page. 我有一个poweshell脚本-它打开了网页-但是想法是它将登录该页面。 It pulls up the page ok, but does not put anything in the login/password box. 它将页面拉好,但未在登录名/密码框中添加任何内容。 I got the getelementbyid'd from google chrome tools. 我从Google chrome工具中得到了getelementbyid'd。

Do you have any idea on how to troubleshoot this script. 您对如何解决此脚本有任何想法吗? Like in perl or bash I can put in echo statements. 像在perl或bash中一样,我可以放入echo语句。 i can use set -x to check the output. 我可以使用set -x来检查输出。 I want to see it the script is entering in the login and password. 我想看看脚本是在登录名和密码中输入的。

param
         (
           [parameter(Mandatory=$true)]
           [ValidateNotNull()]
           $ID
         )


$username = "casper"
$password = "passworD"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$false
$ie.navigate("http://casperweb.stm.swissbank.com:8080/cds/marketAccessAcctLimits.jsp?Term=$ID")
while($ie.ReadyState -ne 4) {start-sleep -m 1}
$ie.Document.getElementById("userName").value= "$username"
$ie.Document.getElementById("password").value = "$password"
$ie.Document.getElementById("submitButton").Click()
start-sleep 20
$ie.Document.body | Out-File -FilePath c:\UBS\DEV\web.txt

Are you getting a specific error message? 您是否收到特定的错误消息? Without being able to access your page it's difficult to determine if the element id is correct. 无法访问您的页面,很难确定元素ID是否正确。 Your code and post prompted me to try something similar and I only saw the issue you described when I wasn't entering the correct element id of the fields I was trying to populate. 您的代码和帖子促使我尝试类似的操作,但是当我没有输入要填充的字段的正确元素ID时,才看到您描述的问题。

I found the below articles helpful for inspecting the element and getting the correct ID. 我发现以下文章有助于检查元素并获取正确的ID。

http://kb.oboxthemes.com/articles/how-to-get-css-styles-for-elements/ http://kb.oboxthemes.com/articles/how-to-get-css-styles-for-elements/

https://stackoverflow.com/a/9435732/5587481 https://stackoverflow.com/a/9435732/5587481

I'm not an expert at this in any way so hopefully I understand the issue at hand correctly here :) 我无论如何都不是专家,所以希望我在这里正确理解了这个问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM