繁体   English   中英

使用Selenium WebDriver C#获取元素的位置

[英]Get location of element using selenium webdriver c#

我无法获取元素的位置。 这是我到目前为止定义的元素

[FindsBy(How = How.Id, Using = "column-a")] 
private IWebElement _columnA;
private string [] startLoc;
private string [] endLoc;

然后在方法中,我有:

startLoc[0] = _columnA.Location.X.ToString() + " " + _columnA.Location.Y.ToString();

在运行时,我在Framework.dll中收到类型为'System.NullReferenceException'的异常,但未在用户代码中处理

附加信息:对象引用未设置为对象的实例。

好吧,您不能使用未实例化的字符串数组:

// Don't do this:
string[] foo;
foo[0] = "bar";     // throws System.NullReferenceException

要初始化数组,请使用字符串数组初始化程序:

var foo = new string[1]; // string array with 1 empty element
foo[0] = "bar";

但是在C#中,使用Collections更为优雅。 也许您可以重新设计代码并使用List<string>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM