从 Java 到 C# 的代码
Code from Java to C#
如何将以下代码从 Java 重写为 C#?
public List<IWebElement> findAll (By by)
{
return driver.FindElements(by);
}
如果我复制粘贴,我得到以下错误:
cannot implicitly convert type 'System.Collections.ObjectModel.ReadOnlyCollection<OpenQA.Selenium.IWebElement>' to 'System.Collections.Generic.List<OpenQA.Selenium.IWebElement>'
谢谢!
第一个解决方案是将方法签名更改为:
public IList<OpenQA.Selenium.IWebElement> findAll (By by)
第二种解决方案是调用.ToList()
扩展方法:
return driver.FindElements(by).ToList();
如何将以下代码从 Java 重写为 C#?
public List<IWebElement> findAll (By by)
{
return driver.FindElements(by);
}
如果我复制粘贴,我得到以下错误:
cannot implicitly convert type 'System.Collections.ObjectModel.ReadOnlyCollection<OpenQA.Selenium.IWebElement>' to 'System.Collections.Generic.List<OpenQA.Selenium.IWebElement>'
谢谢!
第一个解决方案是将方法签名更改为:
public IList<OpenQA.Selenium.IWebElement> findAll (By by)
第二种解决方案是调用.ToList()
扩展方法:
return driver.FindElements(by).ToList();