splinter icon indicating copy to clipboard operation
splinter copied to clipboard

browser.find_by_css(..) doesn't work with non HTML elements

Open osroca opened this issue 14 years ago • 11 comments

I tried to use find_by_css over a SVG element and it doesn't return anything. However JQuery script makes the trick

browser.find_by_css('svg#my_id > g ') # this doesn't return anything
browser.evaluate_script("$('svg#my_id > g').length") # returns the number of g elements in svg#my_id

osroca avatar Mar 15 '12 08:03 osroca

Just one question, Is there a way to run lettuce + splinter tests without internet connection? (sometimes I'm working offline and I can't run my test suite)

By the way, great job!

osroca avatar Mar 18 '12 10:03 osroca

Splinter and Lettuce do not depend on internet connection as far as I know. But if you want to access resources on the web, you need an internet connection, of course.

Can you give more details?

hltbra avatar Mar 27 '12 15:03 hltbra

@hltbra My question is related to this issue https://github.com/cobrateam/splinter/issues/20. Firefox (11.0) looks that has the preference "network.manage-offline-status" set to false as default. I tried to set this value in a firefox profile I have for tests purpose and it doesn't work. If I'm offline (without internet connection) the browser instance doen't start the navigation. I can't figure out how to work where I'm offline.

osroca avatar Apr 06 '12 14:04 osroca

@osroca Well, you succeed selecting by jquery but not by css. JQuery's selector looks a lot like css selector, but they aren't equal. Try this: 1- go to your brower (if it's firefox you'll need have firebug installed) press F12 2- go to the console 3- (with jquery loaded in page) type $('svg#my_id > g') and see if it returns something 4- now try using css selector: $$('svg#my_id > g') if it doesn't return anything it's not splinter fault, it's the css selector which doesn't support this kind of element.

FYI: $ is jquery $$ is css selector

bernardobarreto avatar May 02 '12 18:05 bernardobarreto

Thanks! I'll try it and I'll come back to you with the result.

El 02/05/2012, a las 20:23, Bernardo Barreto escribió:

@osroca Well, you succeed selecting by jquery but not by css. JQuery's selector looks a lot like css selector, but they aren't equal. Try this: 1- go to your brower (if it's firefox you'll need have firebug installed) press F12 2- go to the console 3- (with jquery loaded in page) type $('svg#my_id > g') and see if it returns something 4- now try using css selector: $$('svg#my_id > g') if it doesn't return anything it's not splinter fault, it's the css selector which doesn't support this kind of element.

FYI: $ is jquery $$ is css selector


Reply to this email directly or view it on GitHub: https://github.com/cobrateam/splinter/issues/139#issuecomment-5468474

osroca avatar May 02 '12 18:05 osroca

@bernardofire I tried your suggestion about check $$ queries with firebug, and it works and return what is expected, but the equivalent find_by_css doesn't return any item. Try it yourself here: https://bigml.com/gallery/model/4f89c50f035d0737d300001e

  • $$('svg#tree_svg > g > g.prediction_node') returns an array of 18 g elements
  • browser.find_by_css('svg#tree_svg > g > g.prediction_node') returns an empy array

I need to count how many g elements I have in the view, so, if find_by_css works I could count using len(..), I'm using the following instead: browser.evaluate_script("$('svg#tree_svg > g > g.prediction_node').length")

osroca avatar May 17 '12 16:05 osroca

@osroca thanks for testing, but anyway, splinter uses selenium to select stuff, so if it's not finding anything this selenium issue.

What do you think @andrewsmedina, @fsouza and others, should we close this issue?

bernardobarreto avatar May 18 '12 01:05 bernardobarreto

If it is a selenium issue, it should be reported to selenium. May we link the issue in the selenium tracker here?

Let's keep this issue open until the problem is fixed within selenium (or we find that selenium won't fix it).

@osroca: I think you can continue to use javascript while this css selector does not work with splinter.

fsouza avatar May 18 '12 01:05 fsouza

@fsouza, @bernardofire I don't know if it is a bug. I don't kwno well how the jquery selector engine works, but I think that svg#tree_svg isn't a valid css selector.

@osroca you can get the #tree_svg element by id and to use a nested find_by to get the "g.prediction_node" elements:

browser = Browser('chrome') browser.visit("https://bigml.com/gallery/model/4f89c50f035d0737d300001e") elements = browser.find_by_css("#tree_svg")[0].find_by_css("g.prediction_node") len(elements) 18

It works on chrome and firefox.

andrewsmedina avatar May 18 '12 03:05 andrewsmedina

@fsouza, @bernardofire I don't know if it is a bug. I don't kwno well how the jquery selector engine works, but I think that svg#tree_svg isn't a valid css selector.

Yes, it is.

http://www.w3.org/TR/selectors/#id-selectors

Forget about jQuery, use querySelector in your browser, it works:

>>> document.querySelector("svg#tree_svg")
<svg id="tree_svg" width="730" height="935px">

fsouza avatar May 18 '12 03:05 fsouza

Closing, since this isn't a splinter issue or something we can easily patch over.

javascript-error avatar Jul 19 '21 22:07 javascript-error