- Notifications
You must be signed in to change notification settings - Fork 781
Add support for jQuery selectors (uses window's jQuery) #161
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
Conversation
| Hi, Guys, does this mean the latest build of selenium Library will have this? I submitted an issue a while back to have jQuery incorporated back in to selenium2Library of Robot Framework as all our tests in RC use jQuery very heavily. Please advice. Thank You |
| If you build it from my fork, it will work (unless I checked in a typo.. see my comment above!). But I doubt Ryan will merge this; IMO it's not the correct solution, it's just a place to start. |
| I've made some time starting yesterday to review issues for the next release. I will look this over. - Ed |
| Nice ! |
| Ed, any updates on this? |
| Hey Guys
|
| @hemakannan Again this is an upstream choice by the Selenium WebDriver team to remove support for jQuery/sizzle. As this is the robotframework-selenium2library we are tying together existing functionality within WebDriver making it accessible through Robot Framework. So if it doesn't exist within WebDriver I'm not sure we should try to shove it in. @tenwit Do you have any tests for this? |
| Hi Ed
|
| @hemakannan Let's see his code as I am wandering if there is a solution that works like @peritus's solution for ajax wait. The solution in this pull request looks clean, in that is fits into the Sel2Library locator strategy but I guessing that it will fail in that browser.execute_script(js) won't return the same thing as browser.find_elements_by_XXXXXXXXX. That's why I want to see a test for this solution. |
| I don't, but I'm sure I can cobble a few together in no time; it's just a selector prefix. But not until Tuesday, most likely :( |
| Hi Ed, tenwit :) |
| @hemakannan Your missing the point in that all the old SeleniumLibrary did was use the jQuery functionality provided by Selenium RC. And actually this was only implemented by a jQuery plug-in which is why I think you had to use the add_location_strategy in the first place. The SeleniumLibrary wasn't doing anything special but simply acting as a bridge between Robot Framework and the functions provided by Selenium RC. Selenium WebDriver dropped support for jQuery/sizzle thus we don't have anything to bridge to or to connect into directly with Selenium2Library. What I suspect @tenwit will find in testing this change is that the execute javascript will return success but not return a Selenium WebElement which is what selenium needs to perform any function on like click element. It will be trying to "click successful javascript return value" which is wrong. |
| I see. Gotcha.
|
| @hemakannan I wish it was as simple as doing something like SeleniumLibrary but tying in the locator with the actions is really problematic with Selenium dropping support for jQuery/sizzle. |
| :( well I hoped to see if it was as easy as adding like selenium 1 lib. All I just hoped that we could just literally migrate all of our tests like But looks like its not possible. We created a user keyword like this "wait until page contains elements with
|
| @hemakannan xpath has a "similar" 'contains' functionality. I use the quotes around "similar" because I am not sure if jQuery and xpath use the exact same syntax but it is something to look into. |
| @emanlove I haven't written any tests but I am using this patch while migrating our tests to Selenium2Library. It's working fine, as far as it goes. It only works because we use jQuery on all our pages, of course, but that's good enough for now. |
| Ok I had a look at the code and here is my .02. I've written something similar and I'm about 99% sure that the execute_script will indeed return the same thing as find_element. So I think we are OK on that point. And I like the fact that this is using a separate location strategy so it doesn't interfere will anybody who doesn't want to use it. Now as tenwit correctly points out in his initial comment you have to have jQuery bundled with your application for this to work. So it doesn't achieve the same functionality that was available in Selenium 1. Thus since I think that is really the goal I would probably add a check if jQuery exists and if it doesn't exist load it. That way this functionality will work on pages / applications that do not have jQuery installed. The downside of that approach is it requires a second round trip from each and every call, which can really slow things down if your a using a remote connection. Thus a different way would be to have a seperate load_jquery keyword that could be called one before any calls using the jQuery location strategy were made... of course there is an issue if the application uses something like prototype where you need to load jQuery with no conflicts so it doesn't overwrite existing frameworks. The way we got around this in the past was with some code like this: this is less than ideal, because it relies on a modified version of jQuery that exists on users system. We could I guess package jQuery with S2L, but it may be better, just to ignore (or at least document) the potential collision issues (read, don't use with prototype.js) and then we could just pull jQuery directly from github and thus always get the latest version. The other thing to document / keep in mind here is that execute_script does not honor the implicit_wait functionality built into Selenium 2. So if you really want to do it write you should build in the implict wait functionality into the js script that you call... i.e. put some sort of loop / retry in the jquery. The ultimate decision I'll leave to however implements it, cause I don't really have time to do it at the moment. |
| Yes tenwit and Jeremy
|
| @hemakannan -- I would suspect that tenwit's fork will work just fine for you. Have you tried your tests against it? |
| Hey Jeremy. No
|
| after you have downloaded / installed the fork, you just use a locator that starts with jquery= or sizzle= and that should trigger the query support. Cheers, On Jan 20, 2013, at 9:54 PM, hemakannan wrote:
|
| Ok will keep you guys posted.
|
| Current version(1.1.0) not support css pseudo class "contains", +1 for jQuery locator. |
| Sorry guys. Been busy. I will let you guys know soon.
|
| Hi Everybody my name is Gabriel and a colleague of Hema, I downloaded and installed the fork for Jquery and i'm pleased to inform you that it worked like a charm. I will like to thank you all for your support and the implementation for this added code. Our transition to webdriver will be made much easier with this addition. Hopefully this fork will be added to an official release soon.. Thank you. |
| Hey Guys, can this be pushed to the regular/main branch so it can be included by default in the builds we get ? |
| I think the only blocker on this was a lack of internal tests. As for a keyword to check to see if jQuery is available this functionality request can be made in a new issue. |
| Sorry guys, completely forgot about this fork! And I've left my dev computer at work this weekend :( I'll write some tests next weekend if noone gets around to it first. I'll just find all the tests for the CSS locator and duplicate them for this one, is that about right? |
Finally back on this, sorry for the delay folks! Still teaching myself python. Duplicated the CSS table locator integration test as starting point and immediately found a bug. Fix is included: wasn't checking for jquery/sizzle prefix in table keywords.
Simple tests for jquery/sizzle locator, built from the existing links and tables tests. Includes moving the previous commit's tests to the sizzle suite, so that only one suite will fail if jquery cannot be loaded. I believe that the tests can be marked non-critical, which might be a good thing since they can fail if jquery cannot be downloaded. I'll look into this soon.
| Right, some basic tests added. They use jQuery's own CDN to fetch jQuery, so the tests will fail if there is no internet access. I'll look into making the tests non-critical tomorrow, assuming I get time. Suggestions on what extra tests to add will be gratefully received, |
Add support for jQuery selectors (uses window's jQuery)
This allows "jquery" and "sizzle" locator prefixes, which delegate to the window's jQuery. Probably not suitable for merging as-is; I think it would be better if jQuery was provided by selenium2library.
But it is easy and probably* works, so I thought I'd share. Maybe it will inspire someone to enhance it.