简体   繁体   中英

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

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 . Maybe you can redesign your code and use a List<string> .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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