Javascript Powershell找不到元素
我尝试登录,然后导航到一个页面,然后在第二个页面上设置元素值并提交它们。但是powershell一直说这些元素不存在。所以为了排除故障,我想将我所在页面的内容写入一个文本文件。下面的脚本创建了一个空白文件。有什么想法吗Javascript Powershell找不到元素,javascript,powershell,Javascript,Powershell,我尝试登录,然后导航到一个页面,然后在第二个页面上设置元素值并提交它们。但是powershell一直说这些元素不存在。所以为了排除故障,我想将我所在页面的内容写入一个文本文件。下面的脚本创建了一个空白文件。有什么想法吗 $ie = New-Object -com InternetExplorer.Application $ie.visible=$true $ie.navigate($URL) while ($ie.Busy -eq $true) { Start-Sleep -M
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate($URL)
while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 1000;
}
$ie.Document.getElementById("userId").value = $username
$ie.Document.getElementByID("userPassword").value=$password
$ie.Document.getElementById("login").Click();
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; }
Start-Sleep -Milliseconds 10000;
#$ie.Document.getElementById("officeList").action ="edit.jsp";
#$ie.Document.getElementById("officeId").value="1234";
#$ie.Document.getElementById("officeList").submit();
$ie.navigate($URL2)
$ie.document.documentelement.innertext |out-file C:\Users\me\Documents\PowerShell\html.txt
您确定您的元素名为userId和userPassword等吗?您可以在浏览器中按F12键时检查它们您确定您的元素名为userId和userPassword等吗?您可以在浏览器中按F12键时检查它们是否对此进行了调试?我在
开始睡眠-10000毫秒设置一个断点,看看实际的浏览器窗口是什么样子。同样,在调用$ie.navigate($URL2)
之后,浏览器窗口是什么样子的?是的,我观看了ie窗口,它有内容。您调试过吗?我在开始睡眠-10000毫秒设置一个断点,看看实际的浏览器窗口是什么样子。同样,在调用$ie.navigate($URL2)
之后,浏览器窗口是什么样子的?是的,我观察ie窗口,它有内容。以后请注意,这不是问题的答案,应该是这里的注释。。我不知道。我制作了如下内容:$IE=newobject-com internetexplorer.application$IE.visible=$true$即导航($2)$ie.fullscreen=$true;start sleep-s 3$IE.Document.getElementById(“login_username”)。value=$username2$IE.Document.getElementById(“login_password”)。value=$password2 start sleep-s 1$IE.Document.getElementById(“login”)。submit()我也有同样的错误,用start sleep解决了我的错误。我不得不调整它们,使之恰到好处。该网站加载速度变慢。以后请注意,这不是问题的答案,应该是这里的第一条评论。。我不知道。我制作了如下内容:$IE=newobject-com internetexplorer.application$IE.visible=$true$即导航($2)$ie.fullscreen=$true;start sleep-s 3$IE.Document.getElementById(“login_username”)。value=$username2$IE.Document.getElementById(“login_password”)。value=$password2 start sleep-s 1$IE.Document.getElementById(“login”)。submit()我也有同样的错误,用start sleep解决了我的错误。我不得不调整它们,使之恰到好处。站点加载速度变慢。。