"System.NullReferenceException: Object reference not set to an instance of an object."
This problem occurs in a coded step, following this kind of pattern:
The first line, where it calls the Find method on the active browser and uses an absolute xpath, works fine. But the second line, calling the Find method on the particular HtmlControl and using a relative xpath to find another element, fails; the variable element2 remains null, and the further coded steps fail with the error above.
I've attached a complete project which uses a very simple test to demonstrate this problem.
8 Answers, 1 is accepted
You just need a small change in the code and it will work as expected:
Just replace ./ with // That way you will find any elements that are relative to the first element.
You can read more about Xpath Syntax in this article.
// - Selects nodes in the document from the current node that match the selection no matter where they are.
I hope this helps.
However, there is a difference between ./ and // notation, so if test studio only supports // notation it is a limitation.
// means to identify any descendant of the current context, while ./ means to identify any child of the current context.
So for example in this sample of html:
If div 1 is the current node, then the following relative xpaths should return different results:
//div should return div 2, div 3 and div4.
./div should return only div 2.
Is there any reason why the ./ notation is not supported by telerik?
I read the following to try and get up to speed on all the element identification things I could. I just can't think of a way to use most of them.
I spent some time investigating the issue with the XPath expression and you are absolutely right that it is not working as expected.
I filed a bug report on this problem, which you can follow in our Feedback Portal. I am sorry for any inconvenience it has probably caused and have updated your Telerik Points accordingly.
Let me know if you need assistance on writing the right Find Expression for some element.
Thank you for your understanding.