【发布时间】:2019-05-25 01:59:53
【问题描述】:
我正在用 c# 做一个小的 selenium 程序。我想等待最多 5 秒来交互按钮或其他东西(如果它可见)。我已经为它编写了一个代码,但是我不能在 static void main 中调用该代码,它说一个对象是必需的非静态字段。我该如何解决 ? 错误:非静态字段、方法或属性 'Program.waitForPageUntilElementIsVisible(By, int)
需要对象引用类程序 { 公共 IWebDriver 驱动程序;
static void Main(string[] args)
{
IWebDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("https://www.mail.com/int/");
IWebElement login = driver.FindElement(By.Id("login-button"));
login.Click();
IWebElement email = driver.FindElement(By.Id("login-email"));
waitForPageUntilElementIsVisible(By.Id("login-email"), 5);
email.SendKeys("CarlosdanielGrossen95@mail.com");
}
public IWebElement waitForPageUntilElementIsVisible(By locator,int maxseconds)
{
return new WebDriverWait(driver, TimeSpan.FromSeconds(maxseconds))
.Until(ExpectedConditions.ElementExists((locator)));
}
}
}
非静态字段、方法或属性 'Program.waitForPageUntilElementIsVisible(By, int) 需要对象引用
【问题讨论】:
-
您需要将
waitForPageUntilElementIsVisible方法设为静态。 -
这次“司机”说不能在静态里面?
标签: c# selenium selenium-webdriver selenium-chromedriver