ZSnake
ZSnake

Reputation: 158

JavascriptExecutor (Selenium WebDriver C#) keeps returning null objects

I'm trying to retrieve HTML elements via jQuery and I keep getting null reference point exception, in every JavascriptExecutor statement I write. Is it me?

Here's my code:

List<Object> list= (List<Object>)(IJavaScriptExecutor)Browser).ExecuteScript("$('tbody').find('tr')");
 list.Count.ShouldBeLessThan(rowsWithNewActivity);

Upvotes: 2

Views: 4242

Answers (1)

JimEvans
JimEvans

Reputation: 27496

You're not returning anything from your JavaScript execution. Try this:

List<object> list = ((IJavaScriptExecutor)Browser).ExecuteScript("return $('tbody').find('tr');") as List<object>;

This should no longer return a null value, but rather should return the list you're looking for.

Upvotes: 7

Related Questions