Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please add support for jQuery in Selenium 2 #77

Closed
hemakannan opened this issue Jul 16, 2012 · 18 comments
Closed

Please add support for jQuery in Selenium 2 #77

hemakannan opened this issue Jul 16, 2012 · 18 comments
Milestone

Comments

@hemakannan
Copy link

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

@j1z0
Copy link
Contributor

j1z0 commented Jul 19, 2012

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

@hemakannan
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Jeremy, any help on this please?

Hema

@j1z0
Copy link
Contributor

j1z0 commented Jul 25, 2012

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

@hemakannan
Copy link
Author

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

Thank you
Hema
On Jul 24, 2012 10:40 PM, "Jeremy Johnson" <
reply@reply.github.com>
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:

#77 (comment)

@hemakannan
Copy link
Author

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

@j1z0
Copy link
Contributor

j1z0 commented Aug 23, 2012

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.

@hemakannan
Copy link
Author

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" notifications@github.com 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//issues/77#issuecomment-7960847.

@hemakannan
Copy link
Author

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

Thank You !
Hema

@bsommardahl
Copy link

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

@hemakannan
Copy link
Author

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
Copy link
Author

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
Copy link
Author

Hey j1z0 Jeremy,
Any updates on this ?

Thanks
Hema

@rbovill
Copy link

rbovill commented Mar 25, 2013

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

@bsommardahl
Copy link

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 notifications@github.com 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//issues/77#issuecomment-15420946
.

@emanlove
Copy link
Member

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

@hemakannan
Copy link
Author

Great news ! Thanks so much guys !
On May 25, 2013 4:33 PM, "Ed Manlove" notifications@github.com 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//issues/77#issuecomment-18453500
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants