SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Please add support for jQuery in Selenium 2

Open hemakannan opened this issue 14 years ago • 18 comments

Is this feasible? We use jQuery a lot. Add Location Strategy was very useful to us in the front. But can the jQuery support be brought back to Selenium2?

Thank You Hema

hemakannan avatar Jul 16 '12 20:07 hemakannan

The removal of jquery or actually just sizzle. Is a design decision by the webdriver team. As such it's upstream from S2L. I'm not against shoe horning it back in from s2l but it will be just that, a shoe horn. Because this really needs to be implemented in the webdriver (server).

If we do it from s2l I think the main issue you would have is the implicit wait functionality would probably not work at all. And we would either require the user to write the JavaScript (not good) or agree on what we want to expose ie just sizzle selectors? What about jquery filters etc...

If the above is acceptable then I would be happy to implement it. (should Be fun :)

Of course if anybody else has other ideas feel free chime in. :)

j1z0 avatar Jul 19 '12 02:07 j1z0

Yes Jeremy, I agree that this is something that webdriver should have a support for. Add Location Strategy was actually contributed by my colleague Radek in Selenium1Lib which is like super duper helpful as we use jQuery a lot in our app and these tests. I just opened a ticket with webdriver folks and see if there is any possiblity of support JQuery in the webdriver as I know there is definitely groups of people who could benefit from this. I don't know if this request will be considered but anyways knowing you can help bringing it back to Sel2Lib is helpful. Also like you mentioned , if anyone has better suggestions on getting jQuery into Sel2Lib, please chime in..

Thank You so much Jeremy for getting back.

Hema

hemakannan avatar Jul 19 '12 14:07 hemakannan

Hi Jeremy, so here is the answer to supporting jQuery in webdriver: https://groups.google.com/forum/?fromgroups#!topic/selenium-users/RK0KqX_QPT4

Its not happening.

hemakannan avatar Jul 19 '12 15:07 hemakannan

Jeremy, any help on this please?

Hema

hemakannan avatar Jul 25 '12 02:07 hemakannan

ok well I can look into developing something. It might take a couple of weeks as I'm pretty slammed with projects right now. I can however give you some quick and dirty code sample that may help you get started / code something up in the mean time.

Here is a very simplistic execute jQuery style function.

    def _execute_jquery(self, script, *args):
        '''basically just executes a script, and if it fails, loads jquery and
        tries the script again'''
        from selenium.common.exceptions import WebDriverException
        browser = self._current_browser()

        logger.info ("execute jquery with script %s" % script)
        try:
            logger.info("executing script %s" % (script))
            retval = browser.execute_script(script, *args)
        except WebDriverException:
            self._load_jquery()
            retval = browser.execute_script(script, *args)
        if retval:
            logger.info( "got retval of %s" % (retval))
            break

        logger.info("returning value")
        return retval

So basically you just pass in the jquery function that you want to call, like:

$(.some_class).filter('visible').get(1);

or whatever. The _execute_jquery function above, if it receives and error will attempt to load jQuery and then re-execute the script.... no need to load jQuery if you application already supports it. But to load jQuery from a local file the function would look like:

    def _load_jquery(self):
        import os
        logger.info("load jquery")
        ROOT = os.path.dirname(__file__)
        LIB_DIR = os.path.join(ROOT, '..', 'lib')
        jquery_file = os.path.join(LIB_DIR, "jquery-latest.min.js")
        jquery_lib = open(jquery_file, 'r').read()

        browser = self._current_browser()
        browser.execute_script(jquery_lib)

Hope that is enough to get you started... like I said I can take this up...I'll look to fully reproduce the add location strategy keyword, but do to my current workload it may take a while.

Cheers, Jeremy

j1z0 avatar Jul 25 '12 02:07 j1z0

Thank you so much !!! will look into the interim solution you provided.

Thank you Hema On Jul 24, 2012 10:40 PM, "Jeremy Johnson" < [email protected]> wrote:

ok well I can look into developing something. It might take a couple of weeks as I'm pretty slammed with projects right now. I can however give you some quick and dirty code sample that may help you get started / code something up in the mean time.

Here is a very simplistic execute jQuery style function.

    def _execute_jquery(self, script, *args):
        '''basically just executes a script, and if it fails, loads jquery
and
        tries the script again'''
        from selenium.common.exceptions import WebDriverException
        browser = self._current_browser()

        logger.info ("execute jquery with script %s" % script)
        try:
            logger.info("executing script %s" % (script))
            retval = browser.execute_script(script, *args)
        except WebDriverException:
            self._load_jquery()
            retval = browser.execute_script(script, *args)
        if retval:
            logger.info( "got retval of %s" % (retval))
            break

        logger.info("returning value")
        return retval

So basically you just pass in the jquery function that you want to call, like:

$(.some_class).filter('visible').get(1);

or whatever. The _execute_jquery function above, if it receives and error will attempt to load jQuery and then re-execute the script.... no need to load jQuery if you application already supports it. But to load jQuery from a local file the function would look like:

    def _load_jquery(self):
        import os
        logger.info("load jquery")
        ROOT = os.path.dirname(__file__)
        LIB_DIR = os.path.join(ROOT, '..', 'lib')
        jquery_file = os.path.join(LIB_DIR, "jquery-latest.min.js")
        jquery_lib = open(jquery_file, 'r').read()

        browser = self._current_browser()
        browser.execute_script(jquery_lib)

Hope that is enough to get you started... like I said I can take this up...I'll look to fully reproduce the add location strategy keyword, but do to my current workload it may take a while.

Cheers, Jeremy


Reply to this email directly or view it on GitHub:

https://github.com/rtomac/robotframework-selenium2library/issues/77#issuecomment-7239262

hemakannan avatar Jul 25 '12 12:07 hemakannan

HI Jeremy, Hope you are doing great. So we did not have time to try this out at our end. But I just wanted to check with you on if you would have time soon to look into putting back location strategy back into Sel2Lib. Please advice.

Thank You Hema

hemakannan avatar Aug 23 '12 03:08 hemakannan

Yeah I plan on doing it. However I'm not sure when I will get the chance. :( I'm pushing hard for another deadline next week at work. Hopefully after that I'll have some time. I'll keep you posted it may be a few weeks.

Jeremy

On Aug 23, 2012, at 11:10 AM, hemakannan wrote:

HI Jeremy, Hope you are doing great. So we did not have time to try this out at our end. But I just wanted to check with you on if you would have time soon to look into putting back location strategy back into Sel2Lib. Please advice.

Thank You Hema

— Reply to this email directly or view it on GitHub.

j1z0 avatar Aug 23 '12 06:08 j1z0

Thank you Jeremy for your support. When you implement this it going to be so easy for us to move sel2lib and run tests without major refactoring.

Thank you so much once again

Hema On Aug 23, 2012 2:06 AM, "Jeremy Johnson" [email protected] wrote:

Yeah I plan on doing it. However I'm not sure when I will get the chance. :( I'm pushing hard for another deadline next week at work. Hopefully after that I'll have some time. I'll keep you posted it may be a few weeks.

Jeremy

On Aug 23, 2012, at 11:10 AM, hemakannan wrote:

HI Jeremy, Hope you are doing great. So we did not have time to try this out at our end. But I just wanted to check with you on if you would have time soon to look into putting back location strategy back into Sel2Lib. Please advice.

Thank You Hema

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHubhttps://github.com/rtomac/robotframework-selenium2library/issues/77#issuecomment-7960847.

hemakannan avatar Aug 23 '12 13:08 hemakannan

Hi Jeremy, Hope all is well with you. Just wanted to check on this with you.

Thank You ! Hema

hemakannan avatar Sep 17 '12 18:09 hemakannan

My team just finished a library that wraps jquery functions for use with Selenium. We just finished our first release, but plan on wrapping ALL of jquery's functions. This library makes it easy to use jquery from your Selenium tests in C#. It makes for MUCH cleaner looking tests. Here's the source code: https://github.com/AcklenAvenue/JQSelenium

bsommardahl avatar Sep 29 '12 15:09 bsommardahl

Hi, Thanks ! I am going to give this a shot this week and will get back to you if I have any questions.

Hema

hemakannan avatar Sep 30 '12 23:09 hemakannan

Hi Byron

That looks really nice for java/c# but it would require binding your library to python (and other languages) and then again to robot framework (since it's written in python). A better approach would be to support the way it use to work in selenium1 by allowing jquery= selectors to be used throughout the existing selenium routines.. Which shouldn't require any binding changes at all?

I am not sure if this would work for my request. Jeremy, any updates on your end for this jquery support ?

hemakannan avatar Oct 11 '12 15:10 hemakannan

Hey j1z0 Jeremy, Any updates on this ?

Thanks Hema

hemakannan avatar Dec 01 '12 01:12 hemakannan

My QA team also needs support for Sizzle (or jQuery), otherwise we will have to rewrite a substantial amount of our tests to use xpath (not-desired) or hope there is a static ID further up the tree we can reference. What is the status of this issue?

Thanks,

Rob

rbovill avatar Mar 25 '13 20:03 rbovill

Check out https://github.com/AcklenAvenue/JQSelenium for a layer over Selenium that uses jQuery internally and gives you a JQ-like syntax in your c# tests.

Byron Sommardahl Feed - http://sommardahl.com Blog - http://awkwardcoder.com Phone - 615-669-8239

On Mon, Mar 25, 2013 at 3:04 PM, rbovill [email protected] wrote:

My QA team also needs support for Sizzle (or jQuery), otherwise we will have to rewrite a substantial amount of our tests to use xpath (not-desired) or hope there is a static ID further up the tree we can reference. What is the status of this issue?

Thanks,

Rob

— Reply to this email directly or view it on GitHubhttps://github.com/rtomac/robotframework-selenium2library/issues/77#issuecomment-15420946 .

bsommardahl avatar Mar 25 '13 23:03 bsommardahl

jQuery and Sizzle support added and has been released within Selenium2Library version 1.2.

emanlove avatar May 25 '13 20:05 emanlove

Great news ! Thanks so much guys ! On May 25, 2013 4:33 PM, "Ed Manlove" [email protected] wrote:

jQuery and Sizzle support added and has been released within Selenium2Library version 1.2.

— Reply to this email directly or view it on GitHubhttps://github.com/rtomac/robotframework-selenium2library/issues/77#issuecomment-18453500 .

hemakannan avatar May 25 '13 20:05 hemakannan