[英]Get location of element using selenium webdriver c#
I cannot get the location of the element. 我无法获取元素的位置。 This is what i have so far I have defined the element 这是我到目前为止定义的元素
[FindsBy(How = How.Id, Using = "column-a")]
private IWebElement _columnA;
private string [] startLoc;
private string [] endLoc;
Then within the method I have: 然后在方法中,我有:
startLoc[0] = _columnA.Location.X.ToString() + " " + _columnA.Location.Y.ToString();
Upon runtime, I get an exception of type 'System.NullReferenceException' occurred in framework.dll but was not handled in user code 在运行时,我在Framework.dll中收到类型为'System.NullReferenceException'的异常,但未在用户代码中处理
Additional information: Object reference not set to an instance of an object. 附加信息:对象引用未设置为对象的实例。
Well, you cannot use a string array that is not instantiated: 好吧,您不能使用未实例化的字符串数组:
// Don't do this:
string[] foo;
foo[0] = "bar"; // throws System.NullReferenceException
To initialize an array, use the string array initializer: 要初始化数组,请使用字符串数组初始化程序:
var foo = new string[1]; // string array with 1 empty element
foo[0] = "bar";
But in C# it is more elegant to use Collections . 但是在C#中,使用Collections更为优雅。 Maybe you can redesign your code and use a List<string>
. 也许您可以重新设计代码并使用List<string>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.