2013-03-14 88 views
1

我有四个单选按钮:如何显示属性

<div class="x1-radio"> 
    <input id = " " type="radio" name=" " value="12345"> 
     <span class=" ">Radio 1 - Good Luck</span> 
<div class="x1-radio"> 
    <input id = " " type="radio" name=" " value="12345"> 
     <span class=" ">Radio 2 - Good Luck</span> 
<div class="x1-radio"> 
    <input id = " " type="radio" name=" " value="12346"> 
     <span class=" ">Radio 3 - Good Luck</span> 
<div class="x1-radio"> 
    <input id = " " type="radio" name=" " value="12347"> 
     <span class=" ">Radio 4 - Good Luck</span> 

由于这些都是单选按钮,我可以选择一次一个。我知道如何使用xpath选择单选按钮:

nPath = '//*[@class="x1-radio"]//span[text() = "Radio 1 - Good Luck"]' 
browser.element(:xpath, nPath).fire_event "onclick" 

此时选择了一个按钮。我想知道的是,我可以如何在“输入”标签中逐个显示属性以进行屏幕显示。

我在这里找到了一些信息: How can I get value of element custom attribute with Watir 但是做不到。

回答

2

这应显示每个input元件value属性的值:

browser.inputs.each {|input| p input.value} 

像这样应该显示相同的信息,但仅用于选中的单选按钮(一个或多个):

browser.inputs.each {|input| p input.value if input.checked} 
+0

感谢。你将如何显示所选单选按钮“输入”标签的值。 – user2134050 2013-03-14 16:15:16

+0

您是否知道选择了哪个按钮,或者您是否必须检查该页面? – 2013-03-14 16:34:42

+0

我无法分辨选择了哪个按钮。如何检查页面?感谢所有的帮助。 – user2134050 2013-03-14 16:58:42