1
有這片提供一個複選框代碼的鏈接下面給T & C.GEB找不到checkbox元素
<div class="checkbox accept_agreement">
<label class="control-label" for="step_data_accept_agreement">
<input type="hidden" name="step_data[accept_agreement]" value="0">
<input type="checkbox" name="step_data[accept_agreement]" id="step_data_accept_agreement" value="1">
<label for="step_data_accept_agreement">
<a target="_blank" href="/lanevillkor/">
<font><font>I agree, have read and stored the terms and conditions</font></font>
</a>
</label>
</label>
</div>
現在,我在斯波克測試使用GEB的工作,我嘗試檢索複選框元素
<input type="checkbox" name="step_data[accept_agreement]" id="step_data_accept_agreement" value="1">
要做到這一點,我已經嘗試了很多事情沒有預期的輸出。我期待像
$("#step_data_accept_agreement").click()
將是非常直接的,但事實並非如此。在另一邊,如果我把$ ("[for='step_data_accept_agreement'] label").click()
它點擊鏈接。
我試圖變得更具體,但沒有看起來正確返回元素。 我最後的嘗試之一是
termsAndConditionsOption(wait: true) { $("#step_data_accept_agreement", name: "step_data[accept_agreement]") }
和錯誤消息,因爲在其他情況下也是如此,在一個句子
元素不可見
我怎麼錯過?
我有類似的問題,我有2個元素具有相同的ID,點擊沒有工作,因爲我點擊了錯誤的元素。嘗試查看'$(「#step_data_accept_agreement」)'返回多少個元素 – Royg
您正在使用哪個驅動程序?當您嘗試點擊該複選框或者什麼都不發生時,您是否會遇到異常?如果您遇到異常,請粘貼stacktrace?總是有Geb的['CheckboxModule'](http://gebish.org/manual/current/#checkbox-module),旨在使檢查複選框變得簡單。 – erdi
感謝您的回覆。要回答每條評論:1. $(「#step_data_accept_agreement」)不返回任何內容。實際上似乎該元素不可見。 2. @erdi感謝您的建議。我將會看看CheckboxModule。但是我想出了一個不同的解決方案。 – b10n1k