Share via


Powershell - automate clicking button on website

Question

Wednesday, June 29, 2016 9:39 PM

Hi, I'm a beginner with PS and having some trouble getting this one figured out.  I'm writing a script to launch Microsoft's Power BI site at logon.  After navigating to a specific report, I want to click on the fullscreen button within the Power BI interface.  The element I'm trying to click is  this:

<button class="enterFullScreenBtn topNavButton" ng-if="fullScreen.fullScreenModeSupported" localize-tooltip="TopNav_FullScreen_Enter" ng-click="enterFullScreen()" title="Enter Full Screen Mode"><i class="glyphicon glyph-small pbi-glyph-fullscreen"></i></button>

My PS code is:

# Set Power BI Fullscreen
$fs = $ie.Document.DocumentElement.getElementsByClassName('button') | Where-Object {$_.class -eq 'enterFullScreenBtn topNavButton'}
$fs.click()

Any thoughts on how I can get this to work?  Right now it throws the following error:

You cannot call a method on a null-valued expression.
At Y:\cholderfield\Powershell Scripts\LaunchWarehouseKPIs.ps1:35 char:1

  • $fs.click()

    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

All replies (5)

Thursday, June 30, 2016 1:35 PM ✅Answered

Thanks for your input... I've figured it out, turns out I was looking for the wrong class name.  If anyone else stumbles on this thread looking for a script to put Power BI into full screen mode, here it is:

# Set Power BI Fullscreen
$fs = $ie.Document.DocumentElement.getElementsByClassName('glyphicon glyph-small pbi-glyph-fullscreen') | Select-Object -first 1
$fs.click()

Wednesday, June 29, 2016 10:26 PM

Frames pages cannot be scripted.  Some pages have multiple forms and documents and will not be scriptable.

Only you can do the analysis necessary to determine if this is possible.

\(ツ)_/


Thursday, June 30, 2016 5:58 AM

It wouldn't be a PowerShell solution, but I've done a lot of such tasks with SIKULI. It's a java application using Python syntax to write code with images. The SIKULI command line tool can be called from Powershell.

Look here:

http://sikulix.com/

http://www.sikuli.org/


Thursday, June 30, 2016 6:11 AM

If you can do it with that tool then why look at PowerShell.

In the end we cannot much help without access to the website you are trying to access.

As I pointed out, many websites cannot do this because they use methods that cannot ne accessed by firing a click event.  If it can be done only you can discover toe method used on the web page.

\(ツ)_/


Friday, July 1, 2016 2:06 AM

Hi,

Thank you for taking the time to update the result. Your sharing might be helpful for other people who has the similar problem.

Best Regards,
Eve Wang

Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Support, contact [email protected].