I have a login routine at the start of an automated test which, once the URL as loaded, enters a site ID, a username and a password before hitting login.
The problem is that login is being clicked before the password gets entered resulting in a failed login - the test is tripping over itself in its haste!
In the old JS days, I'd use browser.wait(nnnn)
which would work well. So not so much waiting for an element to be present so much as waiting for SendKeys to do its stuff.
Is there a c# equivalent to browser.wait()?
Here's the (Experimental) code - actual data has been removed.
[TestFixture]
public class Chrome_Sample_test
{
private IWebDriver driver;
public string homeURL;
[Test(Description = "Check SauceLabs Homepage for Login Link")]
public void Login_is_on_home_page()
{
homeURL = "https:/<URL>/";
driver.Navigate().GoToUrl(homeURL);
WebDriverWait wait = new WebDriverWait(driver, System.TimeSpan.FromSeconds(15));
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
IWebElement siteID;
siteID = driver.FindElement(By.XPath("//*[@id='winp_SiteID']"));
siteID.SendKeys("<Id>");
IWebElement usrName;
usrName = driver.FindElement(By.XPath("//*[@id='winp_UserID']"));
usrName.SendKeys("<UsrName>");
IWebElement usrPass;
usrPass = driver.FindElement(By.XPath("//*[@id='winp_Password']"));
usrPass.SendKeys("<UsrPass>");
IWebElement logOn;
logOn = driver.FindElement(By.XPath("//*[@id='btn_LogOn']"));
logOn.Click();
//IWebElement element =
//driver.FindElement(By.XPath("//a[@href='/beta/login']"));
// Assert.AreEqual("Sign In", element.GetAttribute("text"));
}
[TearDown]
public void TearDownTest()
{
driver.Close();
}
[SetUp]
public void SetupTest()
{
homeURL = "https://<UL>/";
driver = new InternetExplorerDriver();
}
}
question from:
https://stackoverflow.com/questions/65844637/c-sharp-and-selenium-wait-times 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…