0

I'm using Visual Studio 2015 with Selenium adds for creating web tests, and i need to implement some jQuery code in my C# code. Is there a way for that? if it's help i download jQuery in NuGet package manager, but still i don't know how to implement jQuery code in c#.

I need it to scroll bar created in http://manos.malihu.gr/jquery-custom-content-scroller/ and i go to use

$('#ID').mCustomScrollbar("scrollTo", 200)

I'm begginer so if i need to implement some

using

or other things pls mention :D Thx for all help Janer

Janer
  • 27
  • 7
  • 1
    jquery is a javascript library. You would typically use it in a web page. It has nothing to do with csharp. – davestevens Oct 08 '15 at 12:35
  • 1
    why do you want to write it on server side code? – blogbydev Oct 08 '15 at 12:36
  • 1
    an easy way for having experience with jQuery is web console. You can try it on you project if jQuery is implemented. – Mesut GUNES Oct 08 '15 at 12:41
  • i'm using C# for writing my tests, and that scrollbar is created in jQuery, so if jQuery belongs to javascript, how i can implement javascript in my code? Is there any possibility?? – Janer Oct 08 '15 at 12:50

3 Answers3

2

Look into ExecuteScript() to execute custom javascript in a browser with selenium:

IWebElement element = driver.FindElement(By.Id("myid"));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].mCustomScrollbar('scrollTo', 200);", element);
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
0

You can't. jQuery is a Javascript library for webdevelopment. You can only use jQuery in Javascript files (or script blocks in your HTML).

Joshua Bakker
  • 2,288
  • 3
  • 30
  • 63
  • and using java in c# either is not possible in simple way. I figured it out few min ago. so i just need to write my tests in java directly. Thx for trying help me :) – Janer Oct 08 '15 at 13:38
  • You can't use javascript* (if you mean that) in C# no, only in ASP.NET (which is used to create websites). If you mean java, I don't know how it's related to this question. – Joshua Bakker Oct 08 '15 at 13:40
  • Try not to simply say 'It cannot be done'. The entire point is there are cases where you may need to use javascript inside C#. It's possible, see this this example: https://www.c-sharpcorner.com/UploadFile/7d3362/use-javascript-function-in-window-application-C-Sharp1/ Not the cleanest example, but it displays using javascript in C# (though admittedly not in the same context as within this question). – Allen Clark Copeland Jr Mar 03 '20 at 18:17
0

My finally code to use jQuery based on alecxe code is

string cssElement = driver.FindElement(By.||all the way u want||).GetAttribute("id");
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("$(\"#\"+\"" + cssElement + "\".replace(/:/g,\"\\\\:\")).mCustomScrollbar('scrollTo',[200,0]);");

it's working (for me). If some problem try first change barlocation and element location. it's for vertical bar ;)

I hope that help someone in future

Eray Balkanli
  • 7,752
  • 11
  • 48
  • 82
Janer
  • 27
  • 7