简体   繁体   English

如何在不使用已弃用的 ExpectedConditions 的情况下在 selenium 测试中遇到诸如“元素不可交互”异常之类的异常

[英]How to encounter exceptions like “element not interactable” exception in selenium test without use of ExpectedConditions which are deprecated

I'm turning tests in selenium which i corrected to be ok, but sometimes the test give me ko due to different exceptions like "ElementClickInterceptedException" and "element not interactable".我正在用 selenium 进行测试,我更正为没问题,但有时由于“ElementClickInterceptedException”和“元素不可交互”等不同的异常,测试给了我ko。 My question is : Is there any way to encounter this kind of problem?我的问题是:有没有办法遇到这种问题? I have found different codes on internet that use : Thread.Sleep and ExpectedConditions but the second method use deprecated code and the first one i'm not sure is good method because it will make the test very slow and will be running in large period of time.我在互联网上发现了不同的代码使用:Thread.Sleep 和 ExpectedConditions 但第二种方法使用不推荐使用的代码,第一种我不确定是好方法,因为它会使测试非常慢并且会在很长一段时间内运行时间。

The ExpectedConditions are indeed deprecated but there is a workaround for it that replaced them: ExpectedConditions确实已弃用,但有一种解决方法可以替代它们:

Wait.Until(c => c.FindElement(By.Id("elem-id")));

Basically you can add any lambda expression in the Wait.Until function.基本上,您可以在Wait.Until函数中添加任何 lambda 表达式。

Check the documentation here: https://www.selenium.dev/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_Support_UI_DefaultWait_1_Until__1.htm在此处查看文档: https : //www.selenium.dev/selenium/docs/api/dotnet/html/M_OpenQA_Selenium_Support_UI_DefaultWait_1_Until__1.htm

Repeatedly applies this instance's input value to the given function until one of the following occurs: the function returns neither null nor false the function throws an exception that is not in the list of ignored exception types the timeout expires重复将此实例的输入值应用于给定函数,直到发生以下情况之一: 函数既不返回 null 也不返回 false 函数抛出一个异常,该异常不在被忽略的异常类型列表中 超时到期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何处理 selenium c# 中的元素不可交互异常 - how to handle element not interactable exception in selenium c# 在页面对象模型设计中如何使用硒ExpectedConditions? - How do you use selenium ExpectedConditions in a page object model design? 如何为 Selenium 添加自定义 ExpectedConditions? - How to add custom ExpectedConditions for Selenium? 如何在没有 DesiredCapabilities(已弃用)的情况下使用 AndroidDriver 或 IOSDriver? - How to use AndroidDriver or IOSDriver without DesiredCapabilities(which is deprecated)? OpenQA.Selenium.ElementNotInteractableException:元素不可交互 - OpenQA.Selenium.ElementNotInteractableException : element not interactable ElementNotInteractableException:元素不可交互 C# Nunit Selenium - ElementNotInteractableException : element not interactable C# Nunit Selenium 修复元素不可交互 Selenium C# - Fix Element not Interactable Selenium C# C# chromedriver 中的“元素不可交互”异常 - 'element not interactable' exception in C# chromedriver 如何在不引发异常的情况下使用Selenium'Until'函数? - How can I use Selenium 'Until' function without throwing an Exception? Selenium C# ElementNotVisibleException:元素不可交互但元素实际上是可见的 - Selenium C# ElementNotVisibleException: element not interactable but the element is actually visible
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM