繁体   English   中英

使用Powershell在Edge中激活Power BI全屏模式

[英]Use Powershell to activate Power BI fullscreen mode in Edge

因此,我需要在我们办公室的各种显示器上显示一堆Power BI报告。 我曾经认为使用Edge会是最好的选择,因为它与Power BI一起使用效果最好,因为两者都是MS产品?

我为此使用了以下Powershell脚本:

# 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

}

该脚本旨在打开Edge(然后将打开我需要的默认启动页面),将Edge设置为全屏模式,单击Power BI全屏按钮,等待20秒钟,旋转选项卡,刷新选项卡。

我唯一无法工作的是从该网站的全屏按钮中单击Power BI全屏模式。 我不断出现以下错误:

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

有人有想法么? 干杯

据我所知,Microsoft Edge将不支持COM自动化接口,但是Internet Explorer支持它。 因此,我们无法使用Powershell从Microsoft Edge中找到网页元素。

因此,作为解决方法,您可以使用IE浏览器打开网站并找到打开PowerBI报告的按钮。

代码如下:

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

对于Microsoft Edge浏览器自动化方案,我们可以使用Microsoft Edge WebDriver来实现。 您可以参考以下C#示例:

安装Edge WebDriver后,可以打开Edge浏览器,并使用FindElementById或FindElementsByClassName方法查找按钮,然后调用元素click()方法打开报告。

    /*
    * 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();
    }

有关Microsoft Edge WebDriver的更多详细信息,请查看以下文章:

WebDriver for Microsoft Edge入门

通过WebDriver将自动化测试带到Microsoft Edge

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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