WebDriver and C# - NoSuchElement exception

后端 未结 3 1961
天命终不由人
天命终不由人 2021-01-13 06:29

I have the following code for selecting an option from given list and it usually works, but sometimes it fails with NoSuchElement exception on the second if. I was under the

3条回答
  •  萌比男神i
    2021-01-13 06:44

    well, I am Java guy, so I will not provide you the code, but rather the algorithm:

    • Yours code (I think) should check, if the element is displayed and if not, wait extra 2,5 secs
    • The reason it fails is, that sometimes it takes more than first 2,5 secs to display the element. In that case, check for if the element is displayed will throw exception

    So, basically you should do some exception handling in the for loop and catch this exception and do nothing. In Java its done by try and catch block. But because I dont know C# you will have to find out how its done in this language

提交回复
热议问题