From af913356cf76fce9b4b2f834eaa7f875d73923b1 Mon Sep 17 00:00:00 2001 From: Arik Jones Date: Tue, 5 May 2020 15:26:51 -0500 Subject: [PATCH] Add Exists property to Element class that catches the timeout exception and returns false. --- Basin/Basin.csproj | 4 ++-- Basin/Selenium/Element.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Basin/Basin.csproj b/Basin/Basin.csproj index b9c6ffb..0883400 100644 --- a/Basin/Basin.csproj +++ b/Basin/Basin.csproj @@ -2,7 +2,7 @@ BasinFramework - 0.0.6 + 0.0.7 Arik Jones BasinFramework net472;netcoreapp2.1 @@ -14,7 +14,7 @@ Git selenium, browser, automation, framework true - TBD + Add Exists property that catches the timeout so that we can return false. true Library true diff --git a/Basin/Selenium/Element.cs b/Basin/Selenium/Element.cs index c8768c1..d521059 100644 --- a/Basin/Selenium/Element.cs +++ b/Basin/Selenium/Element.cs @@ -72,6 +72,21 @@ private IWebElement Locate } } + public bool Exists + { + get + { + try + { + return Current.Displayed; + } + catch (WebDriverTimeoutException) + { + return false; + } + } + } + private IWebElement Current => Locate ?? throw new NullReferenceException("Element could not located because it was null"); private IWebElement CurrentParent => _parentElement ?? throw new NullReferenceException("Parent element could not be located because it was null");