Created
April 15, 2020 19:33
-
-
Save jimevans/a67e25344290abdefa4396005a6ac074 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public bool IsVisible | |
| { | |
| get | |
| { | |
| try | |
| { | |
| WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(3)); | |
| ActiveCompaniesGrid = wait.Until(d => d.FindElement(ActiveCompaniesGridId)); | |
| return ActiveCompaniesGrid.Displayed; | |
| } | |
| catch (WebDriverTimeoutException) | |
| { | |
| return false; | |
| } | |
| } | |
| } |
something which finally makes sense to me is that the wait.Until() will throw the timeout exception if the element is not found during the time period.
I think I got led on a false trail from some online articles that were catching nosuchelement exceptions...
@Snogren Also, the thing that a lot of people miss is that the Until method returns a value. It returns the return value of the lambda function passed into it, and that return value can be either a reference type (a subclass of System.Object), or a boolean.
Yes I had missed that too. Very interesting. Thank you again for all your time, this was exciting to talk to you and learn.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
So you're waiting for the existence of that locator within the process of creating a new instance of the iwebelement.
If the wait period expires, the timeout exception will be thrown, in which case you can catch it and return false.
nosuchelement is already handled within the wait class.