[英]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的更多詳細信息,請查看以下文章:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.