Skip to content

Instantly share code, notes, and snippets.

@jimevans
Created April 15, 2020 19:33
Show Gist options
  • Save jimevans/a67e25344290abdefa4396005a6ac074 to your computer and use it in GitHub Desktop.
Save jimevans/a67e25344290abdefa4396005a6ac074 to your computer and use it in GitHub Desktop.
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;
}
}
}
@Snogren
Copy link

Snogren commented Apr 15, 2020

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.

@Snogren
Copy link

Snogren commented Apr 15, 2020

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.

@Snogren
Copy link

Snogren commented Apr 15, 2020

I think I got led on a false trail from some online articles that were catching nosuchelement exceptions...

@jimevans
Copy link
Author

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

@Snogren
Copy link

Snogren commented Apr 16, 2020

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