[英]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.