[英]invalid argument exception when creating ChromeWebElement using a string
When I create a ChromeWebElement
using a string
at runtime, I get当我在运行时使用
string
创建ChromeWebElement
时,我得到
The best overloaded method match for 'OpenQA.Selenium.Chrome.ChromeWebElement.ChromeWebElement(OpenQA.Selenium.Chrome.ChromeDriver, string)' has some invalid argumentsResult message:
public class Browser {
public static dynamic driver,d;
public Browser(BrowserDriver browserDriver, FeatureContext featureContext)
{
_browserDriver = browserDriver;
driver = _browserDriver._driver;
_featureContext = featureContext;
_featureContext.Add("driver", driver);
}
[StepArgumentTransformation]
public ChromeWebElement convertToWebElement(string c)
{
d = _featureContext.Get<IWebDriver>("driver");
return new ChromeWebElement(Browser.d,c);
}
According to the this , the constructor only takes two arguments ChromeDriver
and string
. 据此,构造函数只需要两个 arguments
ChromeDriver
和string
。 So what is wrong here?那么这里有什么问题呢?
Look at this line看这条线
new ChromeWebElement(Browser.d,c);
in this case在这种情况下
c
is string c
是字符串Browser.d
is dynamic (declared here public static dynamic d;
) Browser.d
是动态的(此处声明为public static dynamic d;
) but the constructor of ChromeWebElement
requires:但是
ChromeWebElement
的构造函数需要:
public ChromeWebElement(
ChromeDriver parent,
string elementId
)
Change declaration of d
to将
d
的声明更改为
private static IWebDriver d;
or even better, remove that declaration and use甚至更好的是,删除该声明并使用
public ChromeWebElement convertToWebElement(string elementId)
{
IWebDriver parent = _featureContext.Get<IWebDriver>("driver");
return new ChromeWebElement(parent, elementId);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.