2

假设我有这样的 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| ...}
4

1 回答 1

5

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

browser.radios.each {|radio| p radio.parent.img.src if radio.set?}
# => "http://s3.amazonaws.com/test005.jpg"
于 2013-05-04T08:14:12.570 回答