This is the code:
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible
$username="name.surname#myemail.com"
$password="MyPassword"
$ie.Navigate("https://service.post.ch/zopa/dlc/app/?service=dlc-web&inMobileApp=false&inIframe=false&lang=fr#!/main")
While ($ie.Busy -eq $true) {Start-Sleep -Seconds 3;}
$usernamefield = $ie.document.getElementByID('isiwebuserid')
$usernamefield.value = "$username"
$passwordfield = $ie.document.getElementByID('isiwebpasswd')
$passwordfield.value = "$password"
$Link = $ie.document.getElementByID('actionLogin')
$Link.click()
while($ieobject.Busy) { Start-Sleep -seconds 10 }
$ie.Quit()
As you can see from the video the website post.ch opens up but then the window closes even if I set Start-Sleep -seconds 10 before $ie.Quit()
This makes me think that probably the script is working but not sure what happens in the next page.
The browser just closes.
Any idea what's going on?
You can also create an account on that website if you wan to test.
The error says:
Exception from HRESULT: 0x800A01B6
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:12 char:1
+ $usernamefield = $ie.document.getElementByID('isiwebuserid')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:13 char:1
+ $usernamefield.value = "$username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Exception from HRESULT: 0x800A01B6
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:15 char:1
+ $passwordfield = $ie.document.getElementByID('isiwebpasswd')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:16 char:1
+ $passwordfield.value = "$password"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Exception from HRESULT: 0x800A01B6
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:18 char:1
+ $Link = $ie.document.getElementByID('actionLogin')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], NotSupportedException
+ FullyQualifiedErrorId : System.NotSupportedException
You cannot call a method on a null-valued expression.
At C:\Users\fmv\Desktop\Import Ref Data scripts\getPosteDataUAT.ps1:19 char:1
+ $Link.click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
While ($ie.Busy -eq $true) is not a valid way to wait until a website is loaded. Unfortunately, there is no standard way of telling that a website is fully loaded. Javascript could load things at any time later, or permanently.
So you have to define your "fully loaded" state by yourself. For example, you could wait until a certain element exists.
Besides that, it looks like the website doesn't load in IE at all. So the elements will never be available in this browser (at least on my machine). It works in Edge and Firefox, though.
If the website loads in your IE, you can replace While ($ie.Busy -eq $true) ..., by just Start-Sleep -Seconds 10. So that you definitely wait 10 s. This should be enough for the elements to load (if they do it at all). And the errors should be gone. If that works, look for a better method to wait.
Related
I am using powershell to automate login page but when i navigate to login console page there is no $ie.document method is visible. and showing the null error.
Method present for console page are :
CreateObjRef
Equals
GetHashCode
GetLifetimeService
GetType
InitializeLifetimeService
ToString
Code I am using is :-
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true # Make it visible
While ($ie.Busy -eq $true) {Start-Sleep -Seconds 7;}
$ie.Navigate("https://matlktwlsapp001:16311/ibm/console/")
start-sleep -s 2;
$ie | gm;
$qw = $ie.document.getElementById("overridelink");
$qw.click();
Error:-
You cannot call a method on a null-valued expression.
At line:7 char:1
+ $qw = $ie.document.getElementById("overridelink");
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
At line:8 char:1
+ $qw.click();
+ ~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
Kindly Help!!
I am trying to automate the IE link where I am logging into the webpage and selecting some dropdown option on that. I am able to login to the link but not able to select the option from dropdown.
while ($ie.Busy -eq $true -or $ie.Document -eq $null ){Start-Sleep -seconds 1;}
$dropDown = $ie.Document.getElementById("state-area").contentDocument.getElementById("state-status")[1].selected = $true
Write-Host("Trying to select the dropdown")
$dropDown = $ie.Document.getElementById("state-area").contentDocument.getElementById("state-status").FireEvent("Ready")
Output:
You cannot call a method on a null-valued expression.
At C:\Documents\TestScript4.ps1:51 char:13
+ $dropDown = $ie.Document.getElementById("state-area").contentDocument.getElement ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Trying to select the dropdown
You cannot call a method on a null-valued expression.
At C:\Documents\TestScript4.ps1:59 char:1
+ $dropDown = $ie.Document.getElementById("state-area").contentDocument.getElement ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
$sumList= New-Object System.Collections.Generic.List[int]
$eventList = New-Object System.Collections.Generic.List[string]
$preSumList= New-Object System.Collections.Generic.List[int]
$threadInitDelay = [int]$commaSplit[++$eventIndex].Split(':')[1].Trim()
$preProcessTime = [int]$commaSplit[++$eventIndex].Split(':')[1].Trim()+[int]$commaSplit[++$eventIndex].Split(':')[1].Trim()+$commaSplit[[int]++$eventIndex].Split(':')[1].Trim()
$respTime = [int]$commaSplit[++$eventIndex].Split(':')[1].Trim();
$index =$eventList.FindIndex({param([string]$s) return $s -like 'hi'})
if($index -eq -1){
$eventList.Add($eventName)
$sumList.Add($threadInitDelay)
$respSumList.Add($respTime)
Getting this error:
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:151 char:19
+ $sumList.Add <<<< ($threadInitDelay)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:152 char:23
+ $respSumList.Add <<<< ($respTime)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:153 char:23
+ $respMaxTime.Add <<<< ($respTime)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [System.Int32[]] doesn't contain a method named 'Add'.
At D:\Powercel\PowershellPractice.ps1:155 char:19
+ $minTime.Add <<<< ($threadInitDelay)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Could you please help me out?
A possible scenario is that you were testing and actually casted those variables like the error states. The error is not wrong. Those variables are not the list types that you have in your code. I can almost reproduce this issue:
PS M:\Scripts\Inno\Output> [int[]]$sumlist = 5,5
PS M:\Scripts\Inno\Output> $sumlist.GetType().Fullname
System.Int32[]
PS M:\Scripts\Inno\Output> $sumlist.Add(5)
Exception calling "Add" with "1" argument(s): "Collection was of a fixed size."
At line:1 char:1
+ $sumlist.Add(5)
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : NotSupportedException
PS M:\Scripts\Inno\Output> $sumlist = New-Object System.Collections.Generic.List[int]
While I didn't get the same error as you the point is the type of the variable didn't change even though I tried to recasted it. That is because of property of the variable explained in this answer by PetSerAl. Have a look at the command Get-Variable sumlist | ft Name,Attributes and you should see System.Management.Automation.ArgumentTypeConverterAttribute. Removing the variable and starting again I get your expected behavior.
PS M:\Scripts\Inno\Output> Remove-Variable sumlist
PS M:\Scripts\Inno\Output> $sumlist = New-Object System.Collections.Generic.List[int]
PS M:\Scripts\Inno\Output> $sumlist.Add(5)
PS M:\Scripts\Inno\Output> $sumlist.GetType().FullName
System.Collections.Generic.List`1[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]
Hi I am trying to connect to sharepoint online and publish calender using the data from a SQL Table and I am getting the following exception , please advise.The same code works fine with slight modification on a on prem sharepoint server I have added sharepointonline for the authentication but it is failing with the error.
[System.Reflection.Assembly]::LoadFile ("C:\MOSSLibrary\Microsoft.SharePoint.Client.dll") | Out-Null
[System.Reflection.Assembly]::LoadFile("C:\MOSSLibrary\Microsoft.SharePoint.Client.Runtime.dll") | Out-Null
$username = "XXXXXX"
$url = "XXXXXX"
$pass= cat C:\text.txt | ConvertTo-SecureString
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$Pass)
$Context.Credentials = $Creds
$web = $Context.Web
$Context.Load($web)
$Context.Load($splist)
$splist = $Context.web.Lists.GetByTitle("XXXX")
$ItemCreateInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
####Some Data coming from SQL Server DB into $table########
$table = $result.Tables[0];
foreach ($row in $table)
{
Write-Host $row.Item("changetitle") $row.Item("status");
$Item1 = $splist.AddItem($ItemCreateInfo)
$Item1["Title"] = "test"
Write-host $date
$Item1.Update()
$Context.ExecuteQuery()
}
Exception
New-Object : A constructor was not found. Cannot find an appropriate
constructor for type Microsoft.SharePoint.Client.ClientContext. At
C:\MOSSLibrary\testingpublish.ps1:15 char:12 + $Context = New-Object
Microsoft.SharePoint.Client.ClientContext($site ... +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : CannotFindAppropriateCtor,Microsoft.PowerShell.Commands.NewObjectCommand
The property 'Credentials' cannot be found on this object. Verify
that the property exists and can be set. At
C:\MOSSLibrary\testingpublish.ps1:17 char:1 + $Context.Credentials =
$Creds + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound You cannot call a method on a null-valued expression. At
C:\MOSSLibrary\testingpublish.ps1:20 char:1 + $Context.Load($web) +
~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At
C:\MOSSLibrary\testingpublish.ps1:21 char:1 + $Context.Load($splist)
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At
C:\MOSSLibrary\testingpublish.ps1:22 char:1 + $splist =
$Context.web.Lists.GetByTitle("XXXXXXX") +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
It seems Assemblies are not loading correctly.
[System.Reflection.Assembly]::LoadFile ("C:\MOSSLibrary\Microsoft.SharePoint.Client.dll") | Out-Null
[System.Reflection.Assembly]::LoadFile("C:\MOSSLibrary\Microsoft.SharePoint.Client.Runtime.dll") | Out-Null
Instead of above, try following
Add-Type -Path "C:\MOSSLibrary\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\MOSSLibrary\Microsoft.SharePoint.Client.Runtime.dll"
PS: Make sure that C:\MOSSLibrary\ contains following two .dll's
Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.Runtime.dll
I have a web page with the following code relevant to the button:
<td width=300 align=left>Click here to run the batch tool:</td>
<td align='left' width=100><input id="Submit1" type="submit" value="Run" onClick='showSts();'/></td>
And my attempts to programmatically press it from Powershell using this code:
$username='username' $password='password'
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true
$ie.Navigate("name of Web site")
while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}
# $usernamefield = $ie.Document.getElementByID('memberemail')
# $usernamefield.value = $username
# $passwordfield = $ie.Document.getElementByID('memberpassword')
# $passwordfield.value = $password
$submitebutton=$ie.Documentelement.getElementByclassname('submit1') | Select-Object -First
$submitebutton.click()
Gives this error:
You cannot call a method on a null-valued expression. At
C:\Users\zkf4bi4\Documents\houdini_click.ps1:15 char:1
+ $submitebutton=$ie.Documentelement.getElementByclassname('submit1') | Select-Ob ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At
C:\Users\zkf4bi4\Documents\houdini_click.ps1:16 char:1
+ $submitebutton.click()
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Any ideas on how to proceed? I'm an experienced developer but am new to Powershell
Well, I can't help but notice that you're calling GetElementsByClassName but 'Submit1' is the elements id. I suspect the error message is trying to tell you that $submitebutton is null. You might find this question an almost exact duplicate.