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

4
  • 1
    jquery is a javascript library. You would typically use it in a web page. It has nothing to do with csharp. Commented Oct 8, 2015 at 12:35
  • 1
    why do you want to write it on server side code? Commented Oct 8, 2015 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. Commented Oct 8, 2015 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?? Commented Oct 8, 2015 at 12:50

3 Answers 3

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);
Sign up to request clarification or add additional context in comments.

Comments

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).

3 Comments

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 :)
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.
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: c-sharpcorner.com/UploadFile/7d3362/… Not the cleanest example, but it displays using javascript in C# (though admittedly not in the same context as within this question).
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

Comments

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.