微调器的可见性为真,但微调器关闭后,微调器的隐性无法按预期工作

问题描述 投票:0回答:1

我正在使用Selenium c#自动化Web应用程序。

登录后,我必须处理显示在主页中的微调器。

我已经给予明确的等待

wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(LocatorSelect(locator,locatorvalue)));

结果通过并且脚本等待该元素可见。

但是在验证微调器可见性之后,我正在验证同一元素的不可见性。

但是即使我给出了10秒,该元素仍要等待30-40秒以上。然后大约40秒后,它不会引发任何错误,并且继续执行脚本而没有任何异常

public void Spinner_Check(string locator, string locatorvalue)
{
    int count = 1;

    WebDriverWait waits = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    waits.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(LocatorSelect(locator, locatorvalue)));

    while (count > 0)
        {



        waits.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(By.XPath(locatorvalue)));
        IList<IWebElement> spinner_element = driver.FindElements(By.XPath(locatorvalue));
        int size = spinner_element.Count;
            if (size != 1)
            {
                count = 0;
                WriteLine("pass", "Spinner is dismissed for the page");
                break;
            }
        }
}

所以我如何避免那么多等待时间,并在从页面中删除微调框后立即执行脚本。

脚本中的一些观察结果:

  1. 当我检查html时,当元素可见时,我可以看到display属性的样式为'Block'。但是在从用户界面中取消了微调框之后,我可以看到,xpath在搜索区域中未显示任何元素:// iframe / parent :: body // div [text()='Loading ..']

  2. 出于调试目的,我设置了在微调器从页面中退出后等待可见的元素。然后我可以看到超时异常和NoSuchElement异常被触发。

c# selenium selenium-webdriver webdriverwait expected-condition
1个回答
0
投票

您需要考虑几件事:

  • 尚不清楚您是否有单独的测试来验证旋转器的可见性,但旋转器的可见性是有效的用例。因此,只有InvisibilityOfElementLocated()可以解决您的目的。
  • Spinner_Check方法看起来是一个完整的开销,您可以仅用一行代码来替换它。

解决方案

要验证InvisibilityOfElementLocated,例如spinner,您可以使用以下解决方案:

new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(SeleniumExtras.WaitHelpers.ExpectedConditions.InvisibilityOfElementLocated(LocatorSelect(locator, locatorvalue)));

参考

您可以在以下位置找到几个相关的讨论:

© www.soinside.com 2019 - 2024. All rights reserved.