0

I would like to use Selenium (with Firefox) to load a page and find those elements that have a particular event (dragleave) attached to them. I thought this would be easy but for some reason I don't find anything useful with Google.

I can easily loop through all relevant elements:

foo = driver.find_elements_by_css_selector("div")

I have tried get_attribute("dragleave") on members of foo in a for loop but it doesn't find anything. Any ideas?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Richard Clark
  • 221
  • 1
  • 3
  • 11
  • I assume you mean event-handlers, and not events. Do you want only the ones that are defined within the html (`
    `), or also the ones defined from the javascript code?
    – Dean Fenster Jul 11 '16 at 16:03
  • Preferably everything. I have no control over how the page is rendered, and I need to execute some tests in it. I am not a HTML guru, but as I can't find any of the elements via "view page source" but they are all there with "inspect element", I reckon they are generated in Javascript code. – Richard Clark Jul 11 '16 at 16:07
  • I'm pretty sure this isn't built into selenium, and you'll have to go over the DOM and call `getEventListeners` for each element... Maybe someone else will have a better idea. – Dean Fenster Jul 11 '16 at 16:13
  • @DeanFenster: ... and the reason for all this is that the page will be rendered differently depending on navigation to the page. There is exactly one field, whose name and class I don't exactly know unless writing code that branches a lot, that has this event attached. I thought it would have been simpler to loop through all elements to find it instead of trying to predict its id. – Richard Clark Jul 11 '16 at 16:13
  • Not because of it rendering differently, but because event handlers don't have to show up in the html (even if it created dynamically). `$('#someelement').click(do_something)` will never show up as an attribute in the html, even in the "inspect element" view. – Dean Fenster Jul 11 '16 at 16:16
  • you can get all the event listeners using `getEventListerners(node or element)` try using execute_script in selenium and the above function. – bhansa Jul 11 '16 at 16:35

1 Answers1

1

You might want to try to get_attribute("innerHTML") on members of foo and search for containing "dragleave"

Moe Ghafari
  • 2,227
  • 1
  • 12
  • 17
  • I have tried that but innerHTML does not have anything related to any event on any element. This was my initial avenue of investigation but it didn't help in this particular case. – Richard Clark Jul 12 '16 at 10:55