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()
TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87

2 Answers2

0

this should help you :

$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() 

note : when you are running the script second time on ie it will not find the tag because language is already changed

ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17
  • thanks for the time i have been checked with this as well but problem is still same... – aditya_rahatekar Mar 22 '17 at 06:43
  • @aditya what is the language in ie , if it's already marathi then it won't find the hyperlink.if that is the case just change it back to english and close ie before running the script – ClumsyPuffin Mar 22 '17 at 06:44
  • this looks so fine when you are testing with power shell, but ones you saved it to and tries to run it, it stuck in the $ie.readyState loop – aditya_rahatekar Mar 22 '17 at 06:46
0

Try to get Admin Access before running script

Use Below Script before running your script. It will Provide you admin access to run your Script

$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;

}

Prateik
  • 16
  • 1