如何获取图像源值

时间:2013-05-03 20:59:05

标签: ruby watir-webdriver

假设我有这样的HTML:

<div class="out-radio">
    <div class="in-radio">
        <input type="radio" value = "12345">
        <label
        <span           
            <div
                <img src="http://s3.amazonaws.com/test001.jpg">
            </div>
        </span
    </label
    </div>
    <div class="in-radio">
        <input type="radio" value = "12346">
        <label
        <span           
            <div
                <img src="http://s3.amazonaws.com/test002.jpg">
            </div>
        </span
    </label
    </div>
    <div class="in-radio">
        <input type="radio" value = "12347">
        <label
        <span           
            <div
                <img src="http://s3.amazonaws.com/test003.jpg">
            </div>
        </span
    </label
    </div>
    <div class="in-radio">
        <input type="radio" value = "12348">
        <label
        <span           
            <div
                <img src="http://s3.amazonaws.com/test004.jpg">
            </div>
        </span
    </label
    </div>
    <div class="in-radio">
        <input type="radio" value = "12349">
        <label
        <span           
            <div
                <img src="http://s3.amazonaws.com/test005.jpg">
            </div>
        </span
    </label
    </div>
</div>

如果我想显示所选单选按钮的value,我会这样做:

browser.element(:xpath, '//*[@class = "in-radio"]').inputs.each {|input| puts value if input.checked?}

如何显示所选单选按钮的src? 我有什么方法可以提出:

browser.element(:xpath, '//*[@class = "in-radio"]').(inputs,imgs).each {|input,img| ...}

1 个答案:

答案 0 :(得分:5)

如果您选择最后一个单选按钮:

browser.radios.each {|radio| p radio.parent.img.src if radio.set?}
# => "http://s3.amazonaws.com/test005.jpg"