4

Summary:

I'm doing some automation testing for a webapp (using Selenium), and I'm trying to capture a mailto:link (specifically one of its query parameters) that gets generated by javascript during an onclick event. Currently the only way I can think of to do this is to duplicate the logic into my test function. This is not ideal because it means I'll have to update the logic in the tests if it ever changes in the webapp. My question is: can you think of a better way?

Details:

Here's how the webapp is working:

  • listen for click event on a div
  • if the event's target is the "email button" generate a mailto: URI based on current state
  • set window.location = [generated URI] in JavaScript

Unfortunately, as you can see, this URI generation happens as a result of an onclick event and just sets the window.location to that URI, so it's not setting it as an href attribute on an anchor (or any attribute on any other) element that I can query the DOM for.

I also haven't had any luck finding an event that fires as a result of the window.location being set to a mailto: URI that might have the URI as one of its properties... am I maybe forgetting one?

Any ideas?

JKing
  • 807
  • 5
  • 14
  • I guess you considered [`window.onbeforeunload`](https://developer.mozilla.org/en/DOM/DOM_event_reference/beforeunload)? – Petr Janeček Jun 28 '12 at 14:19
  • yeah, it didn't seem to fire `beforeunload` or `unload`... I think it doesn't consider itself to be (re/un)loading anything because it knows the browser is going to handle the `mailto` URI in a different window/application. – JKing Jun 28 '12 at 18:08
  • Could the code that generates the URI also place it somewhere in the DOM so Selenium can access it? e.g. in a data attribute or a hidden field? – jabbett Mar 14 '14 at 15:34
  • Try logging the event object. Perhaps somewhere along the bubbling a callback function added the URI to a parameter in the event object itself, which would be optimal for accessing in your web app. – Patrick Roberts Sep 18 '14 at 03:23

1 Answers1

-1

Have you tried calling the function that's on the onclick manually usinge a storeEval and analyzing the return value?

DMart
  • 2,401
  • 1
  • 14
  • 19