Powershell脚本;单击javascript链接
我正在编写一个登录脚本,它将位于后台并将串行端口数据传递到网页。 除了最后一次点击,我所有的东西都正常工作了。根据这两个员额: 这是我的剧本:Powershell脚本;单击javascript链接,javascript,powershell,serial-port,Javascript,Powershell,Serial Port,我正在编写一个登录脚本,它将位于后台并将串行端口数据传递到网页。 除了最后一次点击,我所有的东西都正常工作了。根据这两个员额: 这是我的剧本: # Variables $username = "user" $password = "pass" $item = "" $portnumber = "COM6" #open port and wait for data $port = new-object system.io.ports.serialport $portnumber,9600,no
# Variables
$username = "user"
$password = "pass"
$item = ""
$portnumber = "COM6"
#open port and wait for data
$port = new-object system.io.ports.serialport $portnumber,9600,none,8,one
$port | add-member -membertype "NoteProperty" -name "identifier" -value "Serial"
$port.open()
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
Function Login($name,$pass){
$ie.navigate2("http://site/login.aspx")
while($ie.busy) {start-sleep -s 1}
$ie.document.getElementById("LoginName").value= $name
sleep -s 1
$ie.document.getElementById("Password").value = $pass
sleep -s 1
$ie.document.getElementById("LoginBtn").click()
sleep -s 2
}
Function Lookup($itemnumber){
$ie.navigate2("http://site/itemLookup.aspx")
while($ie.ReadyState -ne 4) {start-sleep -s 1}
$ie.document.getElementById("ctl00_PageBody_ItemNumberBox").value = $itemnumber
sleep -s 1
$ie.document.getElementById("ctl00_PageBody_RetrieveButton").click()
while($ie.ReadyState -ne 4) {start-sleep -s 1}
sleep -s 2
$details = @( $ie.document.getelementsbytagname('a')) | where-object {$_.innerText -eq 'Details'}
$details.click()
}
try{
Do{
$itemno = $port.readline()
write-host $itemno
#check for ie not timed-out
if (!($ie.navigate2("http://site/dashboard.aspx"))) {
sleep -s 2
Login -name $username -pass $password
Lookup -itemnumber $itemno
}
else { Lookup -itemnumber $itemno }
}
while ($port.isopen -eq $true)
}#end try
catch{"$_" ; $ie.quit(); $port.close(); $port.dispose(); exit}
在查找函数中,我遇到了问题。我可以在控制台中运行每一行,它工作正常,但作为脚本,它在分配$details变量时失败,因此不会加载最后一页
这是我尝试与之交互的页面元素:
<tr>
<td colspan="4">
<p id="ctl00_PageBody_ItemInfoPara" class="tabletext">This item's status is Normal. [<a href="javascript://" onclick='ViewItemInformation(11770856,false);'">Details</a>]</p>
</tr>
<tr>
<td colspan="4">
此项目的状态正常。[]
这与范围有关吗?或者我只是在错误地与页面交互?
任何帮助都将不胜感激。而不是
$ie.document.getElementById(“ctl00\u PageBody\u RetrieveButton”)。单击()
尝试单击firstchild:$ie.document.getElementById(“ctl00\u PageBody\u RetrieveButton”).firstchild.click()
因为它不是
块,而是其中的
块,所以我能够通过将两个函数合并为一个主函数来实现这一点,所以这似乎是一个范围问题。有没有办法解决这个问题?