我必須在 UI 中可見元素后執行操作,為此我正在使用以下代碼,但 ExpectedConditions 類拋出錯誤,提示當前背景關系中不存在名稱“ExpectedConditions”。請建議。
public void WaitForElementLoad(By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
WebDriverWait wait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(timeoutInSeconds));
wait.Until(ExpectedConditions.ElementIsVisible(by));
}
}
錯誤 CS0234 名稱空間“OpenQA.Selenium.Support.UI”中不存在型別或名稱空間名稱“ExpectedConditions”(您是否缺少程式集參考?)
uj5u.com熱心網友回復:
以下將解決您的問題
確保您已經為您的專案安裝了Selenium.Webdriver和Selenium.Support NuGet packages。你需要Selenium.Support package使用ExpectedCondition
或者
以這種方式解決:
1:使用nuget,搜索DotNetSeleniumExtras.WaitHelpers,
2:將其namespace匯入您的class.
using SeleniumExtras.WaitHelpers
3:然后代碼示例code:
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.Id("element ID")));
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/488593.html
