我嘗試使用機械化(Ruby)訪問表單。 在我的表格上,我有一個Radiobuttons的gorup。 所以我想檢查其中的一個。Nokogiri錯誤:未定義的方法`radiobutton_with' - 爲什麼?
我寫道:
target_form = (page/:form).find{ |elem| elem['id'] == 'formid'}
target_form.radiobutton_with(:name => "radiobuttonname")[2].check
在此行中我想用2 但在這條線的值來檢查單選按鈕,我得到一個錯誤:
: undefined method `radiobutton_with' for #<Nokogiri::XML::Element:0x9b86ea> (NoMethodError)
根據文檔,你的表單應該是'Mechanize :: Form'類,而不是'Nokogiri :: XML :: Element'。你是如何得到'target_form'的? – 2010-03-18 11:06:20
target_form: target_form =(page /:form).find {| elem | elem ['id'] =='formid'} – Newbie 2010-03-18 11:20:46
您應該使用'Mechanize :: Page#form_with'方法來獲取表單。順便說一句,我不確定你的頁面是不是「Mechanize :: Page」。 – 2010-03-18 11:51:20