【问题标题】:C# await Task.Delay Not working as intended with WinForms/SeleniumC# await Task.Delay 不能按预期使用 WinForms/Selenium
【发布时间】:2019-04-20 10:47:42
【问题描述】:

我正在使用 Selenium 和 Winforms 对网站进行测试。 我必须经常在这里和那里使用延迟。 我仍然无法理解可能是什么问题。而且我对整个“死锁”的事情不是那么好,但是我在这里检查了几个答案,并且代码似乎不是死锁的。

所以基本上,这就是函数internal async Task HandleInput() 它的用途是循环遍历文本文件的每一行,然后将其输入到网站。 循环,每个逻辑都正确到位,直到昨天和今天,当我启动 VS 并对应用程序进行检查时,它才被写入 await Task.Delay(1000); 的那一行。 另一方面,Task.Delay(1000).Wait();工作正常。

这就是我从主HandleInput() 函数调用任务函数的方式。

Logger.LogGenericText("starting process...");                    
                await SignInToSite(DriverChrome, Wait, id, pass);

这里是SignInToSite()函数:

功能负责人:public async Task SignInToSite(IWebDriver DriverChrome, WebDriverWait Wait, string id, string pass)

try
        {
            Logger.LogGenericText("Acessing Login URL...");
            DriverChrome.Navigate().GoToUrl("xxxxxxxxxxxxxxxxxxxxx");
            await Task.Delay(1000); //entire program goes to standstill in here, UI isnt struck. 
            Logger.LogGenericText("Passing id and Password to respective fields...");
            Wait.Until(d => d.FindElement(By.Name("username"))).SendKeys(steamId);
            await Task.Delay(1000);
            Wait.Until(d => d.FindElement(By.Name("password"))).SendKeys(pass);                
            Wait.Until(d => d.FindElement(By.Id("UserLogin"))).Click();
            await Task.Delay(3000);
        }
        catch (Exception ex)
        {
            Logger.LogGenericText(ex.ToString());
            return;
        }

我在另一台 PC 上尝试了编译的程序,没有修复。 如果有人能指出正确的方向,我会很高兴。

【问题讨论】:

标签: c# selenium selenium-webdriver task delay


【解决方案1】:

好吧,看来这是某种僵局之类的。但是,我设法通过在每个等待语句之后使用 ConfigureAwait(false) 来修复它。 我使用来自 Nuget 的ConfigureAwait Checker 来快速完成工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    相关资源
    最近更新 更多