简体   繁体   中英

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". 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.

The ExpectedConditions are indeed deprecated but there is a workaround for it that replaced them:

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

Basically you can add any lambda expression in the Wait.Until function.

Check the documentation here: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM