Powershell IE登录自动化无法找到元素ID
有人可以在PowerShell知道为什么我不能找到用户名输入字段使用其ID“user_name”?我曾在其他网站上尝试过这方面的内容,但它一直在努力,但对于这一点,它只是拒绝找到它。我也尝试了IHTMLDocument3_getElementsByName方法和IHTMLDocument3_getElementsByTagName寻找诸如“输入”甚至“div”之类的东西。一些div类弹出,但有很多错过了,我不知道为什么它失踪。请给我看看灯光。Powershell IE登录自动化无法找到元素ID
#ID names
$IDuserName = "user_name"
$IDuserPass = "user_password"
$url = "https://isssupport.service-now.com/"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.navigate($URL)
While ($IE.Busy -eq $true) {Start-Sleep -Milliseconds 1000}
$ie.Document.IHTMLDocument3_getElementByID($IDuserName).Value = $userName
下面是用户名输入字段
<input name="user_name" id="user_name" type="text" class="form-control" value="" autocomplete="off">
页面是内置的JavaScript加载HTML线。如果您尝试在浏览器中未启用JavaScript的情况下打开该页面,则甚至不会看到登录表单。这似乎是IE/PowerShell找到表单及其元素的问题。
但是你所带来的Internet Explorer窗口到前台,并使用Systems.Windows.Forms
这样的页面交互:
#ID names
$IDuserName = "user_name"
$IDuserPass = "user_password"
$url = "https://isssupport.service-now.com/"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate($ie.Name)
Start-Sleep -Milliseconds 500
$ie.navigate($url)
While ($ie.Busy -eq $true) {Start-Sleep -Milliseconds 1000}
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.SendKeys]::SendWait('username');
[System.Windows.Forms.SendKeys]::SendWait('{TAB}');
[System.Windows.Forms.SendKeys]::SendWait('password');
[System.Windows.Forms.SendKeys]::SendWait('{ENTER}');
请问你正在构建脚本的目的是什么?
问候
冈瑟
感谢Guenther的这些信息,它会让我永远找到答案。我最近刚刚加入公司,并被委派自动化一些服务台任务,所以我只是想找出最好的语言来自动化它。似乎Powershell可能不是这项任务最简单的语言。 –
嗨迈克尔,如果你认为你的问题得到解答,请将其标记为这样。此外,如果你进入自动化,我可以推荐[sikulix](http://www.sikulix.com) – gpunktschmitz
'$ ie.Document.getElementByID($ IDuserName).value的= $ userName'通常为我工作。 –