I am trying to write a generic code for "ElementIsVisible" so that the generic code can be used in multiple places. I keep getting this error. How do I correct this?
Error CS1061 'Shared' does not contain a definition for 'SendKeys' and no accessible extension method 'SendKeys' accepting a first argument of type 'Shared' could be found (are you missing a using directive or an assembly reference?
Here is my code
public Shared WaitUntilElementIsVisible(By by)
{
WebDriverWait wait = new WebDriverWait(Driver.Instance.webDriver, TimeSpan.FromSeconds(20));
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(by));
return this;
}
public Page Physician(string physician)
{
var WeekStarted = PrShared.Page.WaitUntilElementIsVisible(By.XPath("//input[@id='fyd_weekStarted']"));
WeekStarted.SendKeys(weekStarted);
return this;
}
**TO TEST**
Test.Page.Physician(Data.WeekStarted)
CodePudding user response:
In WaitUntilElementIsVisible()
you have return this
but you haven't defined what this
is. The wait
in WaitUntilElementIsVisible()
returns an IWebElement
... just return that but you have to change your return type to IWebElement
.
public IWebElement WaitUntilElementIsVisible(By by)
{
WebDriverWait wait = new WebDriverWait(Driver.Instance.webDriver, TimeSpan.FromSeconds(20));
return wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(by));
}
An additional suggestion would be to add a parameter to this method for timeout so that you can adjust the wait time, e.g.
public IWebElement WaitUntilElementIsVisible(By by, int timeout)
{
WebDriverWait wait = new WebDriverWait(Driver.Instance.webDriver, TimeSpan.FromSeconds(timeout));
return wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(by));
}