Call Page button click event using PowerShell

Using the below PowerShell commands we can open a page and trigger the click event written inside the page. I am using ListItemCollectionPosition to run the while based on the ROW Limit configured in the CAML query.

Please customize this as per your requirements.

Add-PSSnapin Microsoft.SharePoint.Powershell
$pageURL = "http://server/sites/rnd/_layouts/15/SPTest/Pages/gridtest.aspx"
$url = "http://server/sites/rnd"
$listName = "List Name";

$web = Get-SPWeb $url
$list = $web.Lists[$listName]

$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.RowLimit = 2
$caml = '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'
$spQuery.Query = $caml
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($pageURL);

while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 1000;
}

Start-Sleep -Milliseconds 5000;

$doc = $ie.document

$viewmoreCNTRL = $doc.getElementByID("ctrlclick")

Start-Sleep -Milliseconds 5000;

do
{
$listItems = $list.GetItems($spQuery)
$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition

foreach($item in $listItems)
{
Write-Output ("Item #" + $item.ID.ToString());
}

$viewmoreCNTRL.click()
Start-Sleep -Milliseconds 60000;
}
while ($spQuery.ListItemCollectionPosition -ne $null)

$web.Dispose();

 

Advertisements

About Joseph Velliah
As a SharePoint Developer my professional interests tend to be technical and SharePoint focused. I run a blog at "SP RIDER" where you can expect to read HOW TOs and scenarios that I run into during my day to day job. I hope my posts will give back a little to the community that is helped me.

Comments are closed.

%d bloggers like this: