简体   繁体   中英

Use Powershell to activate Power BI fullscreen mode in Edge

So I need to display a bunch of Power BI reports on various displays in our office. I had thought that using Edge would be the best for this purpose as it should work best with Power BI seeing as both are MS products?

I have the following Powershell script going for this:

# Open an Edge window
start microsoft-edge:
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('Microsoft Edge')
while(1 -eq 1){
$wshell=New-Object -ComObject wscript.shell;
$wshell.AppActivate('Microsoft Edge'); # Activate on Edge browser
Sleep 2
$wshell.SendKeys('{F11}') #Open Edge in Fullscreen
Sleep 5
$fs = $edge.Document.DocumentElement.getElementsByClassName('glyphicon glyph-small pbi-glyph-fullscreen') | Select-Object -first 1
$fs.click()
Sleep 20; # Interval (in seconds) between switch 
$wshell.SendKeys('^{PGDN}'); # Ctrl + Page Up keyboard shortcut to switch tab
Sleep 1; # Interval (in seconds) between refresh
$wshell.SendKeys('{F5}'); # F5 to refresh active page

}

The script is designed to open Edge (this will then open the default start up pages I need), set Edge to Fullscreen mode, click on the Power BI fullscreen button, wait 20 seconds, rotate tab, refresh tab.

The only thing I cant get to work is to click the Power BI full screen mode from within that website's full screen button. I keep getting below errors:

You cannot call a method on a null-valued expression.
At line:12 char:5
+     $fs = $edge.Document.DocumentElement.getElementsByClassName('glyp ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At line:13 char:5
+     $fs.click()
+     ~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Anyone have any ideas? Cheers

As far as I know, Microsoft Edge will not support the COM automation interface, but Internet Explorer supports it. So, we could not find the web page elements from Microsoft Edge using powershell.

So, as a workaround, you could use the IE browser to open the site and find the button to open the PowerBI report.

Code as below:

//Open IE Browser
$IE=new-object -com internetexplorer.application
//navigate the website.
$IE.navigate2("website url")
$IE.visible=$true

//Open IE in Fullscreen
$IE.FullScreen = $true

// find the hyperlink 
$fs = $IE.document.getElementsByClassName('glyphicon glyph-small pbi-glyph-fullscreen') | Select-Object -First 1

//click the button to open the powerbi report
$fs.click()

For the Microsoft Edge browser automation scenarios, we could use Microsoft Edge WebDriver to achieve it. You could refer to the following C# sample:

After installing the Edge WebDriver, you could open the Edge browser and using the FindElementById or FindElementsByClassName method to find the button, then, call the element click() method to open the report.

    /*
    * This assumes you have added MicrosoftWebDriver.exe to your System Path.
    * For help on adding an exe to your System Path, please see:
    * https://msdn.microsoft.com/en-us/library/office/ee537574(v=office.14).aspx
    */
    static void Main(string[] args)
    {
        /* You can find the latest version of Microsoft WebDriver here:
        * https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
        */
        var driver = new EdgeDriver();

        // Navigate to Bing
        driver.Url = "https://www.bing.com/";

        // Find the search box and query for webdriver
        var element = driver.FindElementById("sb_form_q");

        element.SendKeys("webdriver");
        element.SendKeys(Keys.Enter);

        Console.ReadLine();
        driver.Quit();
    }

More detail about Microsoft Edge WebDriver, please check the following article:

Getting started with WebDriver for Microsoft Edge

Bringing automated testing to Microsoft Edge through WebDriver

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM