我试图点击链接,但没有任何反应。请帮忙!我在哪里弄错了?
我的操作系统,PS和IE版本:
PS Z:\> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 0 10586 117
PS Z:\> gcim Win32_OperatingSystem | select caption,CSDVersion,version,OSArchitecture
caption CSDVersion version OSArchitecture
------- ---------- ------- --------------
Microsoft Windows 7 Профессиональная Service Pack 1 6.1.7601 64-bit
PS Z:\> (Get-ItemProperty -Path 'HKLM:SOFTWARE\Microsoft\Internet Explorer').svcVersion
11.0.9600.18738
这是powershell命令的输出,显示了我需要点击的元素:
PS Z:\> $ie.document.getElementById("ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert").outerHTML
<input name="ctl00$CPH$NP2$gvUserNotepads$ctl06$ibInsert" id="ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert" style="border
-width: 0px; background-color: transparent;" onclick='javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptio
ns("ctl00$CPH$NP2$gvUserNotepads$ctl06$ibInsert", "", true, "Insert", "", false, false))' type="image" alt="Добавить" sr
c="../../../Images/b_add.gif">
PS Z:\> $ie.document.getElementById("ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert") | select Type, Name, ID
type name id
---- ---- --
image ctl00$CPH$NP2$gvUserNotepads$ctl06$ibInsert ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert
以下是我的尝试:
1) $Link = $ie.document.getElementById("ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert") | where-object {$_.type -eq "image"}
$Link.click();
2) $ie.document.getElementById("ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert").click()
这是powershell代码。您可以自己测试(登录/传递是真实的):
$userlogin = "all"
$userpasswd = "1234567"
$loginpage = "http://aszp.gaz-is.ru/aszp2/Autorization/ASZPLogin.aspx?ReturnUrl=%2faszp2%2fDefault.aspx"
$notepad = "http://aszp.gaz-is.ru/aszp2/ARMs/CreateRequest/Notepads/Notepads.aspx"
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $false
$ie.Navigate2($loginpage)
While ($ie.Busy) { Start-Sleep -Milliseconds 400 }
$forms = $ie.Document.forms.namedItem("form1")
$forms.item("Login1_UserName").value= $userlogin
$forms.item("Login1_Password").value = $userpasswd
$ie.document.getElementById("Login1_Button1").click()
While ($ie.Busy) { Start-Sleep -Milliseconds 400 }
$ie.navigate($notepad)
while ($ie.Busy -eq $true) { Start-Sleep -Seconds 1; }
$forms2 = $ie.Document.forms.namedItem("aspnetForm")
$forms2.item("ctl00_CPH_NP2_gvUserNotepads_ctl06_txtTEI1").value= "Petrov"
$forms2.item("ctl00_CPH_NP2_gvUserNotepads_ctl06_txtTEI2").value = "Ivan"
$forms2.item("ctl00_CPH_NP2_gvUserNotepads_ctl06_txtTEI3").value = "Nikolaevich"
$forms2.item("ctl00_CPH_NP2_gvUserNotepads_ctl06_txtTEI6").value = "Driver"
$forms2.item("ctl00_CPH_NP2_gvUserNotepads_ctl06_txtTEI8").value = "photo_321"
$ie.document.getElementById("ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert").click()
While ($ie.Busy) { Start-Sleep -Milliseconds 400 }
$ie.Visible = $true
Here is the link to my server where the simplified code is. Everything works on it
我的链接的示例powershell代码:
$loginpage = "https://allovergeorgia.com/vk/form/input.html"
$ie = New-Object -ComObject InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate2($loginpage)
While ($ie.Busy) { Start-Sleep -Milliseconds 400 }
$ie.document.getElementById("ctl00_CPH_NP2_gvUserNotepads_ctl06_ibInsert").click()
$ie.Document.Body.InnerText
答案 0 :(得分:0)
我找到了原因。 有必要看一下全貌。只有在填写了所有必填字段时才允许发送表单。
我忘记了电话号码字段:$forms2.item("ctl00_CPH_NP2_gvUserNotepads_ctl06_txtTEIP7_txtEAEBDD").value = "911"
将它添加到代码后,一切都很好并且代码有效))