Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

C# and Selenium - wait times

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...