【问题标题】:driver quits when element was not found找不到元素时驱动程序退出
【发布时间】:2017-02-18 18:00:34
【问题描述】:

我正在 Android 设备上使用 C# 和 Appium 测试本机应用程序。 我正在尝试验证元素是否可见。 问题是如果找不到元素,驱动程序退出测试,我想滑动到页面末尾,直到找到对象。 当然,该对象位于页面底部。 我曾经使用 ScrollTo 方法,但它已被弃用。

  public void SWipeUntilelementVisible()
        {
            var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
           
                bool visible = false;
                int counter = 0;
                while (visible == false)
                {
                    if (counter > 0)
                        _driver.Swipe(1200, 1487, 1200, 732, 0);

                    if (isElementVisible(SendRequirement))
                    {
                        visible = true;
                        Console.WriteLine("Visible");
                        break;
                    }
                }
         }
    
          

        public bool isElementVisible(IWebElement Elementid)
        {
            return SendRequirement.Displayed;
        }
    

编辑 这是 Visual Studio 找不到对象时打印的日志。

Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.NotImplementedException' in WebDriver.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'NUnit.Core.NUnitException' in nunit.core.dll
The thread 0x8a8 has exited with code 0 (0x0).
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
The thread 0x27d8 has exited with code 0 (0x0).
The thread 0x1fbc has exited with code 0 (0x0).
The thread 0x16cc has exited with code 0 (0x0).
The thread 0x19d0 has exited with code 0 (0x0).
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.Net.WebException' in System.dll
Exception thrown: 'System.InvalidOperationException' in WebDriver.dll
Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll
Exception thrown: 'NUnit.Core.NUnitException' in nunit.core.dll
The thread 0x1fd8 has exited with code 0 (0x0).
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
Exception thrown: 'System.IO.FileNotFoundException' in mscorlib.dll
The thread 0x2380 has exited with code 0 (0x0).
The thread 0x19fc has exited with code 0 (0x0).
The thread 0x261c has exited with code 0 (0x0).
The thread 0x256c has exited with code 0 (0x0).
The thread 0x26cc has exited with code 0 (0x0).
The program '[8096] te.processhost.managed.exe' has exited with code 0 (0x0).

【问题讨论】:

  • counter 应该做什么?你进入你的while循环,测试counter > 0在你的例子中是假的,因为你的counter是0。你的counter什么都不算,我只能猜测,但似乎你的测试在5秒后放弃了寻找元素并且司机退出考试。 counter++ 在你的 while 循环中可能是解决方案。
  • 这可能是我的下一个错误。但主要的错误实际上是在第一次进入 while 时发生的。当它查找从 isElementVisible 调用的元素时,测试失败,因为它找不到该元素。这没关系。当它没有找到元素时,我想进行滑动(这就是循环的原因),不幸的是,如上所述,测试正在退出,因为它没有找到元素。
  • 您说“测试正在退出”是什么意思?是否抛出异常?测试成功/失败/错误?系统退出?我可以想象你得到一个 NoSuchElementException 因为 display 只是测试一个元素是否可见,而不是它是否存在。你在哪里找到你的元素SendRequirement?或许that 也能帮到你。
  • 它甚至没有得到显示方法。调试时找不到Element(Nosuchelement),然后跳转到Teardown,以便应用driver.quit()。
  • 所以你必须安全地找到元素。按照我上一条评论中的链接并尝试这种方式。如果找不到元素,则必须显示如何定位元素以及元素的实际位置。

标签: c# android selenium appium


【解决方案1】:

似乎问题已解决。问题是在 64 位系统上运行并尝试加载 32 位 dll。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-14
    • 2018-08-15
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 2015-12-27
    • 1970-01-01
    • 2019-07-17
    相关资源
    最近更新 更多