Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FreshWebElement : IWebElement
- {
- private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
- private IWebElement Element;
- private IWebDriver Driver;
- private By FoundBy;
- public string TagName
- {
- get
- {
- try
- {
- return Element.TagName;
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return TagName;
- }
- }
- }
- public string Text
- {
- get
- {
- try
- {
- return Element.Text;
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return Text;
- }
- }
- }
- public bool Enabled
- {
- get
- {
- try
- {
- return Element.Enabled;
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return Enabled;
- }
- }
- }
- public bool Selected
- {
- get
- {
- try
- {
- return Element.Selected;
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return Selected;
- }
- }
- }
- public Point Location
- {
- get
- {
- try
- {
- return Element.Location;
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return Location;
- }
- }
- }
- public Size Size
- {
- get
- {
- try
- {
- return Element.Size;
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return Size;
- }
- }
- }
- public bool Displayed
- {
- get
- {
- try
- {
- return Element.Displayed;
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return Displayed;
- }
- }
- }
- public FreshWebElement(IWebElement Element, IWebDriver Driver, By FoundBy)
- {
- this.Element = Element;
- this.Driver = Driver;
- this.FoundBy = FoundBy;
- }
- public FreshWebElement(IWebDriver Driver, By FoundBy)
- {
- this.Driver = Driver;
- this.FoundBy = FoundBy;
- this.Element = this.Driver.FindElement(this.FoundBy);
- }
- public void SetSearch(IWebDriver Driver, By FoundBy)
- {
- this.Driver = Driver;
- this.FoundBy = FoundBy;
- }
- public void Clear()
- {
- try
- {
- Element.Clear();
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- Clear();
- }
- }
- public void SendKeys(string text)
- {
- try
- {
- Element.SendKeys(text);
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- SendKeys(text);
- }
- }
- public void Submit()
- {
- try
- {
- Element.Submit();
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- Submit();
- }
- }
- public string GetAttribute(string attributeName)
- {
- try
- {
- return Element.GetAttribute(attributeName);
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return GetAttribute(attributeName);
- }
- }
- public string GetCssValue(string propertyName)
- {
- try
- {
- return Element.GetCssValue(propertyName);
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return GetCssValue(propertyName);
- }
- }
- public IWebElement FindElement(By by)
- {
- try
- {
- return Element.FindElement(by);
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return FindElement(by);
- }
- }
- public ReadOnlyCollection<IWebElement> FindElements(By by)
- {
- try
- {
- return Element.FindElements(by);
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- return FindElements(by);
- }
- }
- public void Click()
- {
- try
- {
- Element.Click();
- }
- catch (StaleElementReferenceException E)
- {
- Log.Debug(E.Message, E);
- Element = Driver.FindElement(FoundBy);
- Click();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement