2
我使用Selenium来查找元素并使用文本填充它。当我浏览我的网址时,一个文本框首先显示加载页面的内容。应用程序加载完成后,会显示一个登录用户名/密码。我只想等到显示登录用户名/密码以避免NoSuchElementException。我引用了this post,但无法获得任何解决方案。NoSuchElementException尽管使用WebDriverWait
当我运行测试时,它不会等待元素出现,并立即在x.FindElement(By.Id("UserName")
上失败,并显示NoSuchElementException
。
using (IWebDriver driver = new ChromeDriver(@"<my path>"))
{
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("<my url>");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(600));
var userName = wait.Until(x => x.FindElement(By.Id("UserName")));
userName.SendKeys("username");
IWebElement pass = driver.FindElement(By.Id("Password"));
pass.SendKeys("password");
}
我在做什么错在这里?我应该如何更改我的代码以便在查找之前等待UserName
ID?
谢谢!我结束了只是使用'wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id(“UserName”)));'那工作。 – tnw