B-Mac
B-Mac

Reputation: 61

Get the src value of an audio control using watir-webdriver

I am writing automated tests for a web application using watir-webdriver and rspec. I need to check an audio control has been loaded correctly. For images, I successfully checked the src attribute using this syntax:

$browser.image(:src => "/media/myimage.jpg").present?.should eql(true)

I was hoping to use a similar method to check the audio controls. The web page structure looks like (HTML braces removed):

audio controls="controls" title=""
   source src="/media/R010201/R010201_audio_PhotoTime.ogg" type="audio/ogg "
audio

Note the source element is a child of the audio element. Using interactive Ruby (IRB), I am attempting to find the src tags using watir-webdriver. I have tried the following:

$browser.audio.present?

- returns true.

$browser.audio.(:tag_name => 'source').text

-fails

$browser.element(:tag_name => 'source').src.text

-fails What syntax should I use to get the value in the src attribute?

Upvotes: 2

Views: 425

Answers (3)

pjd
pjd

Reputation: 1173

You should be able to do

$browser.source.attribute_value("src")

and obtain the "file:///media/R010201/R010201_audio_PhotoTime.ogg" value. It worked for me in the page I mocked up.

Upvotes: 1

Justin Ko
Justin Ko

Reputation: 46836

The proper syntax would be:

browser.audio.source.src
#=> "/media/R010201/R010201_audio_PhotoTime.ogg"

If there is only one audio/source on the page, you could simply do:

browser.source.src

However, if there are multiple audio/source, you will need to find a more specific way of locating them. For example, if there is a unique parent div element around the audio element you would do:

browser.div(:id => 'unique_id').source.src

Upvotes: 1

Saifur
Saifur

Reputation: 16201

You are trying to use tagname which is audio in this case I am not a Watir guy but I guess it's worth a shot.

browser.element(:xpath => "//*[@type='audio/ogg ']").attribute_value('src')

See the api doc here and see another SO thread related here

Upvotes: 0

Related Questions