powershell - 如何使用 Powershell 中的 Edge Selenium webdriver 检查窗口是否最小化

标签 powershell selenium selenium-edgedriver

有人会认为这应该是一件容易的事情,但我找不到一种方法来检测 Chrome 边缘 在 Powershell 中,Selenium webdriver 窗口是否最小化。
具体来说,无论窗口处于最大化还是最小化状态,其大小和位置似乎都相同。例如,看下面的例子(从一个正常的非最小化窗口状态开始):

> $driver.manage().Window.size

IsEmpty Width Height
------- ----- ------
  False  1050    708

> $driver.manage().Window.position

IsEmpty  X  Y
-------  -  -
  False 13 18

> $driver.manage().Window.minimize()
> $driver.manage().Window.size

IsEmpty Width Height
------- ----- ------
  False  1050    708

> $driver.manage().Window.position

IsEmpty  X  Y
-------  -  -
  False 13 18
如您所见,即使窗口已最小化,窗口大小和位置也保持不变。
我找不到 isMinimized()方法或类似的东西。
Chromium Edge webdriver 版本是 93.0.961.38。
有任何想法吗?

最佳答案

您可以尝试使用 Selenium 驱动程序执行 JavaScript 以获取视口(viewport)的大小(没有 powershell,但在我们的场景中有效)。

const width  = window.innerWidth || document.documentElement.clientWidth || 
document.body.clientWidth;
const height = window.innerHeight|| document.documentElement.clientHeight|| 
document.body.clientHeight;
引用:
Get the size of the screen, current web page and browser window
用powershell访问WindowVisualState的过程:
Add-Type -AssemblyName UIAutomationClient
$prList = Get-Process -Name "notepad"
$prList | % {
    $ae = [System.Windows.Automation.AutomationElement]::FromHandle($_.MainWindowHandle)
    $wp = $ae.GetCurrentPattern([System.Windows.Automation.WindowPatternIdentifiers]::Pattern)
    echo "Window visual state: $($wp.Current.WindowVisualState)"
}
结果:
Window visual state: Minimized
引用:
Get window state of another process

关于powershell - 如何使用 Powershell 中的 Edge Selenium webdriver 检查窗口是否最小化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69081293/

相关文章:

powershell - 重复将一个文件的内容复制到另一个文件

powershell - Powershell:通过字符串数组过滤文件的内容

powershell - 尝试使用 Powershell 从全局地址列表中删除所有未经许可的用户

c# - MailKit:如何迭代最近的电子邮件以获取具有给定主题的电子邮件

c# - 更改 eBay 页面内容/DOM 的最简单方法

powershell - 数组值 Powershell

c# - 如何在 Selenium 中获取和设置文本编辑器值

selenium - 如何在 selenium C# 中启用 Chromium Edge 浏览器中的 IE 模式?

c# - WebDriver异常: unknown error: MSEdge failed to start: was killed