首页 > 解决方案 > 为什么我的登录一直失败使用流畅的等待,尝试显式但没有奏效?

问题描述

我正在尝试登录我的浏览器,我尝试了显式等待,即 expectedconditions.elementisvisible 但这没有用,所以我走上了 fluentwaits 的路线。起初 fluent1 工作,然后第二次运行 fuentwait 没有工作。在第三次运行时,两者现在都不起作用

public void loginVT(IWebDriver driver)
        {

            _regRep = new UserRegRep(driver);
            driver.Navigate().GoToUrl(_regRep.AppURL);

            DefaultWait<IWebDriver> fluentWait = new DefaultWait<IWebDriver>(driver);
            fluentWait.Timeout = TimeSpan.FromSeconds(30);
            fluentWait.PollingInterval = TimeSpan.FromMilliseconds(3000);
            fluentWait.IgnoreExceptionTypes(typeof(NoSuchElementException));
            IWebElement searchResult = fluentWait.Until(x => x.FindElement(By.Id("Email")));


            _regRep.Email.SendKeys("test@hotmail.com");
            String strFile = System.IO.File.ReadAllText("password.csv");
            _regRep.Password.SendKeys(strFile);
            _regRep.LogInButton.Click();

            //when the user icon is displayed, we have successfully logged in
             DefaultWait<IWebDriver> fluentWait1 = new DefaultWait<IWebDriver>(driver);
            fluentWait1.Timeout = TimeSpan.FromSeconds(30);
            fluentWait1.PollingInterval = TimeSpan.FromMilliseconds(3000);
            fluentWait1.IgnoreExceptionTypes(typeof(NoSuchElementException));
            IWebElement searchResult1 = fluentWait1.Until(x => x.FindElement(By.XPath("//span[text()='User']")));

}

标签: c#selenium-webdriver

解决方案


推荐阅读