我正在尝试为"ElementIsVisible"因此,通用代码可以在多个地方使用。我总是得到这个错误。我如何纠正这个问题?
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?
这是我的代码
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)
在WaitUntilElementIsVisible()
中,你有return this
,但你没有定义this
是什么。WaitUntilElementIsVisible()
中的wait
返回一个IWebElement
…只要返回它,但你必须将返回类型更改为IWebElement
。
public IWebElement WaitUntilElementIsVisible(By by)
{
WebDriverWait wait = new WebDriverWait(Driver.Instance.webDriver, TimeSpan.FromSeconds(20));
return wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(by));
}
另一个建议是为timeout方法添加一个参数,以便您可以调整等待时间,例如
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));
}