1
$ie = new-object -com internetexplorer.application  
$ie.visible=$true

$ie.navigate('https://google.co.in')

while($ie.ReadyState -ne 4)
{
    Write-Host "dom is loading"
    $ie.ReadyState -eq 4
    $ie.ReadyState -eq 3
    $ie.ReadyState -eq 2
    $ie.ReadyState -eq 1
    $ie.ReadyState -eq 0 
     start-sleep -M 100
}
($ie.Document.Document3_getElementsByTagName('a')|where-object{$_.innerText -eq "मराठी"}).click()
4

2 回答 2

0

这应该可以帮助您:

$ie = new-object -com internetexplorer.application

$ie.visible=$true

$ie.navigate('https://google.co.in')

while($ie.ReadyState -ne 4)

{ Write-Host "dom is loading" waiting 
start-sleep -M 100 } 



($ie.Document.IHTMLDocument3_getElementsByTagName('a')|where-object{$_.innerText -eq "मराठी"}).click() 

注意:当您第二次在 ie 上运行脚本时,它不会找到标签,因为语言已经更改

于 2017-03-22T06:39:54.223 回答
0

在运行脚本之前尝试获取管理员访问权限

在运行脚本之前使用下面的脚本。它将为您提供运行脚本的管理员访问权限

$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal = New-Object System.Security.Principal.WindowsPrincipal($myWindowsID);

$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator;

if ($myWindowsPrincipal.IsInRole($adminRole))
{
$Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)";
Clear-Host;
 }
 else {

$newProcess = New-Object System.Diagnostics.ProcessStartInfo "PowerShell";    
$newProcess.Arguments = "& '" + $script:MyInvocation.MyCommand.Path + "'"    
$newProcess.Verb = "runas";    
[System.Diagnostics.Process]::Start($newProcess);   
Exit;

}

于 2017-03-23T06:33:31.040 回答