I have a problem and was wondering if anyone could help. I need to save the source file (the currently loaded source file) of an audio tag. Sounds simple, but here's the catch the source gives a random sound file on every request.

The audio tag is created, source set and played with javascript.

function createAudio() {
    var audio = document.createElement('audio');

    audio.setAttribute('id', 'file_audio')
    audio.setAttribute('controls', 'controls');
    audio.setAttribute('autoplay', 'true');
    audio.setAttribute('hidden', 'true');
    return audio;

function createSource() {
    var source = document.createElement('source');
    var d = new Date();
    source.setAttribute('id', 'file_audio_source')
    source.setAttribute('src', 'file.wav?r=' + d.getTime());
    source.setAttribute('type', 'audio/wav');
    return source;
this.switchAudio = function() {
    var d = new Date();
    if (Modernizr.audio.wav) {
    } else {
        $svjq("#file_audio").append('<embed id="file_audio_embed" name="file_audio_embed" src="file.wav?r=' + d.getTime() + '" autostart="true" cache="false" type="audio/wav" hidden="true" loop="false" enablejavascript="true">');

this.playAgain = function() {
    if (Modernizr.audio.wav) {
    } else {
I need be able to save the currently loaded file in the source. If you access the file url in the browser it returns a different file. With automated processes, such using Watir-WebDriver, Capybara (Capybara-Webkit), Mechanize It still returns a random file.

require 'capybara'
session = Capybara::Session.new(:selenium)
session.click_link 'play sound' #on every click u get a new sound
session.click_link 'play again'

e = session.find_by_id('file_audio_source')

#save the current open page and opens it

#returns different file

#returns different file

require 'Mechanize' 
agent = Mechanize.new{|agent| agent.ssl_version, agent.verify_mode = 'SSLv3', OpenSSL::SSL::VERIFY_NONE}

filedata = agent.get(e[:src]).content
aFile = File.new("/Users/me/Documents/test/test111.wav", 'wb')
Could the file be embedded into the html or cached? And is there a way to get it and save it locally?

Other options include recording from the sound device, (or using the mic to record the sound played, this option is not the ideal solution at all)

Many thanks in advance for any assistance or suggestions shared

I have been struggling with this for far too long =)