2012-08-08 47 views
1

我正在使用watir-webdriver,我試圖從下面的HTML代碼中選擇一個框,例如對於輸入「LC」,但我有一些方法來使它工作。任何人都有任何想法請。感謝Watir:在複選框中選擇一個項目

browser.checkbox(:value => 'LC').set 

錯誤消息 C:/Ruby193/lib/ruby/gems/1.9.1/gems/watir-2.0.4/lib/watir/element.rb:78:在`ASSE rt_exists' :無法找到元素,使用{:值=> 「LC」}(的Watir ::異常::的Un knownObjectException)

代碼

<TD align="right">Reason:&nbsp;&nbsp;</TD> 
        <TD><style type="text/css"> 
select, ul { height: 40px; overflow: auto; width: 205px; border: 1px solid #000; } 
ul { list-style: none; margin: 0; padding: 0; overflow-x: hidden;} 
li { margin: 0; padding: 0; } 
ul li { 
position: relative; 
} 
li ul { 
position: absolute; 
left: 149px; 
top: 0; 
display: none; 
} 
label { display: block; color: WindowText; background-color: Window; margin:0; 
padding:0; width: 100%; } 
label:hover { background-color: Highlight; color: HighlightText; display: block; } 
</style> 

<script type="text/javascript"> 
function appendValue(checkedValue) { 
findFormElement("reason").value = "" 
if(document.getElementById("CS").checked){ 
findFormElement("reason").value= findFormElemen"reason").value+document.getElementById ("CS").id; 
} 
if(document.getElementById("LC").checked){ 
findFormElement("reason").value = findFormElement("reason").value + document.getElementById("LC").id; 
} 
if(document.getElementById("ND").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("ND").id; 
} 
if(document.getElementById("NG").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("NG").id; 
} 
if(document.getElementById("NC").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("NC").id; 
} 
if(document.getElementById("WD").checked){ 
findFormElement("reason").value = findFormElement("reason").value + document.getElementById("WD").id; 
} 
}; 
</script> 
<input name="reason" type="hidden" value></select><ul id="multisel"> 
<li><label for="CS"><input type="checkbox" name="CS" id="CS" onClick="appendValue (&quot;CS&quot;)"/>Cannot Supply Within 2 Hours</label></li> 
<li><label for="LC"><input type="checkbox" name="LC" id="LC" onClick="appendValue(&quot;LC&quot;)"/>Location Closed</label></li> 
<li><label for="ND"><input type="checkbox" name="ND" id="ND" onClick="appendValue(&quot;ND&quot;)"/>No Drivers Available</label></li> 
<li><label for="NG"><input type="checkbox" name="NG" id="NG" onClick="appendValue(&quot;NG&quot;)"/>No Vehicle Group Available</label></li> 
<li><label for="NC"><input type="checkbox" name="NC" id="NC" onClick="appendValue(&quot;NC&quot;)"/>No Vehicles Available</label></li> 
<li><label for="WD"><input type="checkbox" name="WD" id="WD" onClick="appendValue(&quot;WD&quot;)"/>Weekend Delivery</label></li> 
</ul></TD> 

select, ul { height: 40px; overflow: auto; width: 205px; border: 1px solid #000; } 
ul { list-style: none; margin: 0; padding: 0; overflow-x: hidden;} 
li { margin: 0; padding: 0; } 
ul li { 
position: relative; 
} 
li ul { 
position: absolute; 
left: 149px; 
top: 0; 
display: none; 
} 
label { display: block; color: WindowText; background-color: Window; margin: 0; padding: 0; width: 100%; } 
label:hover { background-color: Highlight; color: HighlightText; display: block; } 
</style> 

<script type="text/javascript"> 
function appendValue(checkedValue) { 
findFormElement("reason").value = "" 
if(document.getElementById("CS").checked){ 
findFormElement("reason").value = findFormElement("reason").value + document.getElementById("CS").id; 
} 
if(document.getElementById("LC").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("LC").id; 
} 
if(document.getElementById("ND").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("ND").id; 
} 
if(document.getElementById("NG").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("NG").id; 
} 
if(document.getElementById("NC").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("NC").id; 
} 
if(document.getElementById("WD").checked){ 
    findFormElement("reason").value = findFormElement("reason").value + document.getElementById("WD").id; 
} 
}; 
</script> 
<input name="reason" type="hidden" value></select><ul id="multisel"> 
<li><label for="CS"><input type="checkbox" name="CS" id="CS" onClick="appendValue (&quot;CS&quot;)"/>Cannot Supply Within 2 Hours</label></li> 
<li><label for="LC"><input type="checkbox" name="LC" id="LC" onClick="appendValue(&quot;LC&quot;)"/>Location Closed</label></li> 
<li><label for="ND"><input type="checkbox" name="ND" id="ND" onClick="appendValue(&quot;ND&quot;)"/>No Drivers Available</label></li> 
<li><label for="NG"><input type="checkbox" name="NG" id="NG" onClick="appendValue(&quot;NG&quot;)"/>No Vehicle Group Available</label></li> 
<li><label for="NC"><input type="checkbox" name="NC" id="NC" onClick="appendValue(&quot;NC&quot;)"/>No Vehicles Available</label></li> 
<li><label for="WD"><input type="checkbox" name="WD" id="WD" onClick="appendValue(&quot;WD&quot;)"/>Weekend Delivery</label></li> 
</ul></TD> 

回答

4

的複選框沒有的值;然而他們每個人都有一個id。嘗試

browser.checkbox(:id => 'LC').set 
+0

非常感謝它的工作 – Sal 2012-08-09 07:34:55

+0

你應該接受的答案即可;) – p0deje 2012-08-09 09:01:07

0

在你這裏結束了想取消選擇checbox情況下,方法是明確

相關問題