我正在更新一些以前使用 Selenium 3.141 的 PowerShell 代码。我有以下代码片段:
Add-Type -LiteralPath "$seleniumPath\lib\net48\WebDriver.dll"
Add-Type -LiteralPath "$seleniumPath\lib\net48\WebDriver.Support.dll"
$url = "https://<webpage.com>"
$options = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$options.AddArgument("--disable-gpu")
$driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($options)
[OpenQA.Selenium.Support.UI.WebDriverWait]$wait = New-Object OpenQA.Selenium.Support.UI.WebDriverWait ($driver, [System.TimeSpan]::FromSeconds(60))
$driver.Navigate().GoToURL($url)
$driver.FindElementById("username")
$wait.Until([OpenQA.Selenium.Support.UI.ExpectedConditions]::ElementExists([OpenQA.Selenium.By]::Id('username')))
在 Selenium 4.0 中,FindElementById 不再起作用:
找不到类型 [OpenQA.Selenium.Support.UI.ExpectedConditions]。
据我所知,OpenQA.Selenium.Support.UI.ExpectedConditions 存在于 WebDriver.Support 中,对吧?
环顾四周寻找替代品,我找到了 SeleniumExtras.WaitHelpers,但这可能只适用于 .netstandard2.1?