2017-05-27 27 views
0

获取元素我想作一个自动登录脚本(为我公司,每个员工工作在3台电脑,并有登陆的15个不同的网站和应用 - 所以我需要一个自动登录) PowerShell的通过ALT

$Url = “www.gmail.com” 


$Username=”xxxxxxx” 

$Password=”xxxxxxxx” 


$Executable = "c:\windows\system32\notepad.exe" 

$IE = New-Object -com internetexplorer.application; 
$IE.visible = $true; 
$IE.navigate($url); 


while ($IE.Busy -eq $true) 

{ 

Start-Sleep -Milliseconds 2000; 

} 


$IE.Document.getElementById(“login_nickname”).value = $Username 
$IE.Document.getElementByID(“login_passwort”).value=$Password 



$IE.Document.getElementbyID("login").Click(); 
console.log($img.alt); 

while ($IE.Busy -eq $true) 

{ 

Start-Sleep -Milliseconds 2000; 

} 

Invoke-Item $Executable 

所以,我输入正确的登录名和密码,但我无法点击登录按钮 - 它没有ID。只有ALT值。而按钮是一个超链接。它不工作,如果我使用的getElementById和输入ALT值是登录,但它不工作(下)

$IE.Document.getElementbyID("login").Click(); 
+0

可以共享DOM结构!你玩形式的'HTML'。 –

+0

该行

回答

0

过滤它通过按钮上的文字?

$IE.Document.links | ? {$_.TextContent -eq "login"} 

使用方法如下:

($IE.Document.links | ? {$_.TextContent -eq "login"} | Select -First 1).Click 
+0

因此 > $ IE.Document.links | ? TextContent -eq“登录” 和现在 Click() –

+0

@MarcinFrankowski更新了答案。 – ConnorLSW

+0

Where-Object无法绑定参数FilterScript。无法将类型System.String的Textcontent值转换为类型System.Management.Automation.ScriptBlock。 –

相关问题