gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:13:22 27 4
gpt4 key购买 nike

有人会认为这应该是一件容易的事情,但我找不到一种方法来检测 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com