0

When I enter the following command into the firefox console I get 65. This is the number I want to check with selenium.

$('#grid').data('kendoGrid').dataSource.total()

Is there anyway I can get selenium to check this?

I have tried the following,

To test out javaScript, (this correctly checks title),

IJavaScriptExecutor js = driver as IJavaScriptExecutor;
string title = (string)js.ExecuteScript("return document.title");
Console.Write(var);

I have tried, both failed.

String num = (String)((IJavaScriptExecutor)driver).ExecuteScript("$('#grid').data('kendoGrid').dataSource.total()");
Console.Write(num);

&

IJavaScriptExecutor js = driver as IJavaScriptExecutor;
String script = "$('grid').data('kendoGrid').dataSource.total()";
String num = (String)js.ExecuteScript("return", script);
Console.Write(num);

I'm just using Console.Write to see the output.

6
  • I haven't done a lot with JSE but it looks like you are missing a return with the first query try. Have you tried, String num = (String)((IJavaScriptExecutor)driver).ExecuteScript("return $('#grid').data('kendoGrid').dataSource.total()");? Commented Oct 20, 2015 at 14:49
  • Have you looked at this: stackoverflow.com/questions/25802518/…? Commented Oct 20, 2015 at 14:50
  • i've tried with the return but no luck. I've also tried String num = (String)js.ExecuteScript("return" + script); Commented Oct 20, 2015 at 15:11
  • If it were me... I would do something super simple with jquery in Selenium just to make sure it was working. Maybe something like $(document).find("title").text(); and make sure it returns the correct title. Commented Oct 20, 2015 at 15:21
  • My first bit of code I posted was my test to make sure it works. I like your example though as it's closer what I want it to be. $(document).find("title").text(); works! I'll keep at it anyway! Commented Oct 20, 2015 at 15:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.