This is a migrated thread and some comments may be shown as answers.

.Click events in Custom Code throwing errors

1 Answer 103 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 15 Apr 2011, 09:32 PM
Hello,

I am currently using the WebUI Test Studio QA Edition and am having trouble the the .Click events when I create custom code. I am searching for a button's xpath on the site using Firefinder in Firefox, and it finds the correct xpath. My code for this looks like:

HtmlAnchor logoutLink = Find.ByXPath<HtmlAnchor>("//a[@title='Logout'][1]");
logoutLink.Click(false);

But I keep getting this error:

'[LogoutStep_CodedStep] : Click the log out link'.
InnerException:
System.NullReferenceException: Object reference not set to an instance of an object.'

I'm not sure why this is happening.

Thanks,
Eric

1 Answer, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 18 Apr 2011, 05:33 PM
Hello Eric,

According to the MSDN XPath reference (which is what the tool uses), your specific XPath breaks down to:

1) Find an anchor element (i.e. <a> at any depth from the root
2) That also has the attribute title='Logout'
3) That also has a child element of "1"

This just doesn't sound right to me because:

1) <a> elements don't normally have a title attribute
2) A <1> element is not a legal HTML element

You are probably getting the System.NullReferenceException because Find.ByXPath is not finding what you expect it to find and is returning null as a result. .Click cannot operate on a null, of course.

Can you share with us the HTML surrounding your logout link? Once we see that we can show you the right XPath to find it for you.

All the best,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
General Discussions
Asked by
Eric
Top achievements
Rank 1
Answers by
Cody
Telerik team
Share this question
or